Toniolo and Linder, Equation (3b), real

Percentage Accurate: 94.3% → 99.6%
Time: 12.3s
Alternatives: 32
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 32 alternatives:

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

Initial Program: 94.3% 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.6% accurate, 1.2× speedup?

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

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

    \[\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. *-commutativeN/A

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

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

      \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
    5. un-div-invN/A

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 82.3% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{hypot}\left(\sin ky, \sin kx\right)\\ t_2 := {\sin kx}^{2}\\ t_3 := \mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\\ t_4 := {\sin ky}^{2}\\ t_5 := \frac{\sin ky}{\sqrt{kx \cdot kx + t\_4}} \cdot \sin th\\ t_6 := \frac{\sin ky}{\sqrt{t\_2 + t\_4}}\\ \mathbf{if}\;t\_6 \leq -1:\\ \;\;\;\;t\_5\\ \mathbf{elif}\;t\_6 \leq -0.15:\\ \;\;\;\;\frac{t\_3}{\frac{t\_1}{\sin ky}}\\ \mathbf{elif}\;t\_6 \leq 4 \cdot 10^{-10}:\\ \;\;\;\;\frac{\sin ky}{\sqrt{t\_2 + ky \cdot ky}} \cdot \sin th\\ \mathbf{elif}\;t\_6 \leq 0.995:\\ \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \cdot t\_3\\ \mathbf{elif}\;t\_6 \leq 1:\\ \;\;\;\;t\_5\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\sin th}{t\_1}}{{ky}^{-1}}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (hypot (sin ky) (sin kx)))
        (t_2 (pow (sin kx) 2.0))
        (t_3 (* (fma (* th th) -0.16666666666666666 1.0) th))
        (t_4 (pow (sin ky) 2.0))
        (t_5 (* (/ (sin ky) (sqrt (+ (* kx kx) t_4))) (sin th)))
        (t_6 (/ (sin ky) (sqrt (+ t_2 t_4)))))
   (if (<= t_6 -1.0)
     t_5
     (if (<= t_6 -0.15)
       (/ t_3 (/ t_1 (sin ky)))
       (if (<= t_6 4e-10)
         (* (/ (sin ky) (sqrt (+ t_2 (* ky ky)))) (sin th))
         (if (<= t_6 0.995)
           (*
            (/
             (sin ky)
             (/
              (sqrt
               (fma
                (- 1.0 (cos (* ky 2.0)))
                2.0
                (* 2.0 (- 1.0 (cos (* 2.0 kx))))))
              2.0))
            t_3)
           (if (<= t_6 1.0) t_5 (/ (/ (sin th) t_1) (pow ky -1.0)))))))))
double code(double kx, double ky, double th) {
	double t_1 = hypot(sin(ky), sin(kx));
	double t_2 = pow(sin(kx), 2.0);
	double t_3 = fma((th * th), -0.16666666666666666, 1.0) * th;
	double t_4 = pow(sin(ky), 2.0);
	double t_5 = (sin(ky) / sqrt(((kx * kx) + t_4))) * sin(th);
	double t_6 = sin(ky) / sqrt((t_2 + t_4));
	double tmp;
	if (t_6 <= -1.0) {
		tmp = t_5;
	} else if (t_6 <= -0.15) {
		tmp = t_3 / (t_1 / sin(ky));
	} else if (t_6 <= 4e-10) {
		tmp = (sin(ky) / sqrt((t_2 + (ky * ky)))) * sin(th);
	} else if (t_6 <= 0.995) {
		tmp = (sin(ky) / (sqrt(fma((1.0 - cos((ky * 2.0))), 2.0, (2.0 * (1.0 - cos((2.0 * kx)))))) / 2.0)) * t_3;
	} else if (t_6 <= 1.0) {
		tmp = t_5;
	} else {
		tmp = (sin(th) / t_1) / pow(ky, -1.0);
	}
	return tmp;
}
function code(kx, ky, th)
	t_1 = hypot(sin(ky), sin(kx))
	t_2 = sin(kx) ^ 2.0
	t_3 = Float64(fma(Float64(th * th), -0.16666666666666666, 1.0) * th)
	t_4 = sin(ky) ^ 2.0
	t_5 = Float64(Float64(sin(ky) / sqrt(Float64(Float64(kx * kx) + t_4))) * sin(th))
	t_6 = Float64(sin(ky) / sqrt(Float64(t_2 + t_4)))
	tmp = 0.0
	if (t_6 <= -1.0)
		tmp = t_5;
	elseif (t_6 <= -0.15)
		tmp = Float64(t_3 / Float64(t_1 / sin(ky)));
	elseif (t_6 <= 4e-10)
		tmp = Float64(Float64(sin(ky) / sqrt(Float64(t_2 + Float64(ky * ky)))) * sin(th));
	elseif (t_6 <= 0.995)
		tmp = Float64(Float64(sin(ky) / Float64(sqrt(fma(Float64(1.0 - cos(Float64(ky * 2.0))), 2.0, Float64(2.0 * Float64(1.0 - cos(Float64(2.0 * kx)))))) / 2.0)) * t_3);
	elseif (t_6 <= 1.0)
		tmp = t_5;
	else
		tmp = Float64(Float64(sin(th) / t_1) / (ky ^ -1.0));
	end
	return tmp
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]}, Block[{t$95$2 = N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$3 = N[(N[(N[(th * th), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * th), $MachinePrecision]}, Block[{t$95$4 = N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$5 = N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(kx * kx), $MachinePrecision] + t$95$4), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$6 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(t$95$2 + t$95$4), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$6, -1.0], t$95$5, If[LessEqual[t$95$6, -0.15], N[(t$95$3 / N[(t$95$1 / N[Sin[ky], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$6, 4e-10], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(t$95$2 + N[(ky * ky), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$6, 0.995], N[(N[(N[Sin[ky], $MachinePrecision] / N[(N[Sqrt[N[(N[(1.0 - N[Cos[N[(ky * 2.0), $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] * t$95$3), $MachinePrecision], If[LessEqual[t$95$6, 1.0], t$95$5, N[(N[(N[Sin[th], $MachinePrecision] / t$95$1), $MachinePrecision] / N[Power[ky, -1.0], $MachinePrecision]), $MachinePrecision]]]]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \mathsf{hypot}\left(\sin ky, \sin kx\right)\\
t_2 := {\sin kx}^{2}\\
t_3 := \mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\\
t_4 := {\sin ky}^{2}\\
t_5 := \frac{\sin ky}{\sqrt{kx \cdot kx + t\_4}} \cdot \sin th\\
t_6 := \frac{\sin ky}{\sqrt{t\_2 + t\_4}}\\
\mathbf{if}\;t\_6 \leq -1:\\
\;\;\;\;t\_5\\

\mathbf{elif}\;t\_6 \leq -0.15:\\
\;\;\;\;\frac{t\_3}{\frac{t\_1}{\sin ky}}\\

\mathbf{elif}\;t\_6 \leq 4 \cdot 10^{-10}:\\
\;\;\;\;\frac{\sin ky}{\sqrt{t\_2 + ky \cdot ky}} \cdot \sin th\\

\mathbf{elif}\;t\_6 \leq 0.995:\\
\;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \cdot t\_3\\

\mathbf{elif}\;t\_6 \leq 1:\\
\;\;\;\;t\_5\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{\sin th}{t\_1}}{{ky}^{-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 or 0.994999999999999996 < (/.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 89.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 \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. unpow2N/A

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\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.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-*.f64N/A

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

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

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

        \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
      5. un-div-invN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.149999999999999994 < (/.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.00000000000000015e-10

    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.5

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

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

    if 4.00000000000000015e-10 < (/.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.994999999999999996

    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-sin.f64N/A

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
      10. unpow2N/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 \]
      11. 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 \]
      12. 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 \]
      13. 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 \]
      14. 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 \]
      15. 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 \]
      16. 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 \]
      17. 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 \]
    4. Applied rewrites99.3%

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

      \[\leadsto \frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \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}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \cdot \color{blue}{\left(\left(1 + \frac{-1}{6} \cdot {th}^{2}\right) \cdot th\right)} \]
      2. lower-*.f64N/A

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

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

        \[\leadsto \frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \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}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \cdot \left(\color{blue}{\mathsf{fma}\left({th}^{2}, \frac{-1}{6}, 1\right)} \cdot th\right) \]
      6. unpow2N/A

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

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

      \[\leadsto \frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \cdot \color{blue}{\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)))))

    1. Initial program 2.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. *-commutativeN/A

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

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

        \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
      5. un-div-invN/A

        \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
      6. div-invN/A

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -1:\\ \;\;\;\;\frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \sin th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -0.15:\\ \;\;\;\;\frac{\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin ky}}\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 4 \cdot 10^{-10}:\\ \;\;\;\;\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.995:\\ \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\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 1:\\ \;\;\;\;\frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{{ky}^{-1}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 82.2% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := {\sin ky}^{2}\\ t_2 := \frac{\sin ky}{\sqrt{kx \cdot kx + t\_1}} \cdot \sin th\\ t_3 := {\sin kx}^{2}\\ t_4 := \frac{\sin ky}{\sqrt{t\_3 + t\_1}}\\ t_5 := \frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\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{if}\;t\_4 \leq -1:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;t\_4 \leq -0.15:\\ \;\;\;\;t\_5\\ \mathbf{elif}\;t\_4 \leq 4 \cdot 10^{-10}:\\ \;\;\;\;\frac{\sin ky}{\sqrt{t\_3 + ky \cdot ky}} \cdot \sin th\\ \mathbf{elif}\;t\_4 \leq 0.995:\\ \;\;\;\;t\_5\\ \mathbf{elif}\;t\_4 \leq 1:\\ \;\;\;\;t\_2\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{{ky}^{-1}}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (pow (sin ky) 2.0))
        (t_2 (* (/ (sin ky) (sqrt (+ (* kx kx) t_1))) (sin th)))
        (t_3 (pow (sin kx) 2.0))
        (t_4 (/ (sin ky) (sqrt (+ t_3 t_1))))
        (t_5
         (*
          (/
           (sin ky)
           (/
            (sqrt
             (fma
              (- 1.0 (cos (* ky 2.0)))
              2.0
              (* 2.0 (- 1.0 (cos (* 2.0 kx))))))
            2.0))
          (* (fma (* th th) -0.16666666666666666 1.0) th))))
   (if (<= t_4 -1.0)
     t_2
     (if (<= t_4 -0.15)
       t_5
       (if (<= t_4 4e-10)
         (* (/ (sin ky) (sqrt (+ t_3 (* ky ky)))) (sin th))
         (if (<= t_4 0.995)
           t_5
           (if (<= t_4 1.0)
             t_2
             (/ (/ (sin th) (hypot (sin ky) (sin kx))) (pow ky -1.0)))))))))
double code(double kx, double ky, double th) {
	double t_1 = pow(sin(ky), 2.0);
	double t_2 = (sin(ky) / sqrt(((kx * kx) + t_1))) * sin(th);
	double t_3 = pow(sin(kx), 2.0);
	double t_4 = sin(ky) / sqrt((t_3 + t_1));
	double t_5 = (sin(ky) / (sqrt(fma((1.0 - cos((ky * 2.0))), 2.0, (2.0 * (1.0 - cos((2.0 * kx)))))) / 2.0)) * (fma((th * th), -0.16666666666666666, 1.0) * th);
	double tmp;
	if (t_4 <= -1.0) {
		tmp = t_2;
	} else if (t_4 <= -0.15) {
		tmp = t_5;
	} else if (t_4 <= 4e-10) {
		tmp = (sin(ky) / sqrt((t_3 + (ky * ky)))) * sin(th);
	} else if (t_4 <= 0.995) {
		tmp = t_5;
	} else if (t_4 <= 1.0) {
		tmp = t_2;
	} else {
		tmp = (sin(th) / hypot(sin(ky), sin(kx))) / pow(ky, -1.0);
	}
	return tmp;
}
function code(kx, ky, th)
	t_1 = sin(ky) ^ 2.0
	t_2 = Float64(Float64(sin(ky) / sqrt(Float64(Float64(kx * kx) + t_1))) * sin(th))
	t_3 = sin(kx) ^ 2.0
	t_4 = Float64(sin(ky) / sqrt(Float64(t_3 + t_1)))
	t_5 = Float64(Float64(sin(ky) / Float64(sqrt(fma(Float64(1.0 - cos(Float64(ky * 2.0))), 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))
	tmp = 0.0
	if (t_4 <= -1.0)
		tmp = t_2;
	elseif (t_4 <= -0.15)
		tmp = t_5;
	elseif (t_4 <= 4e-10)
		tmp = Float64(Float64(sin(ky) / sqrt(Float64(t_3 + Float64(ky * ky)))) * sin(th));
	elseif (t_4 <= 0.995)
		tmp = t_5;
	elseif (t_4 <= 1.0)
		tmp = t_2;
	else
		tmp = Float64(Float64(sin(th) / hypot(sin(ky), sin(kx))) / (ky ^ -1.0));
	end
	return tmp
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(kx * kx), $MachinePrecision] + t$95$1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$4 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(t$95$3 + t$95$1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$5 = N[(N[(N[Sin[ky], $MachinePrecision] / N[(N[Sqrt[N[(N[(1.0 - N[Cos[N[(ky * 2.0), $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$4, -1.0], t$95$2, If[LessEqual[t$95$4, -0.15], t$95$5, If[LessEqual[t$95$4, 4e-10], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(t$95$3 + N[(ky * ky), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$4, 0.995], t$95$5, If[LessEqual[t$95$4, 1.0], t$95$2, N[(N[(N[Sin[th], $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] / N[Power[ky, -1.0], $MachinePrecision]), $MachinePrecision]]]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := {\sin ky}^{2}\\
t_2 := \frac{\sin ky}{\sqrt{kx \cdot kx + t\_1}} \cdot \sin th\\
t_3 := {\sin kx}^{2}\\
t_4 := \frac{\sin ky}{\sqrt{t\_3 + t\_1}}\\
t_5 := \frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\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{if}\;t\_4 \leq -1:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;t\_4 \leq -0.15:\\
\;\;\;\;t\_5\\

\mathbf{elif}\;t\_4 \leq 4 \cdot 10^{-10}:\\
\;\;\;\;\frac{\sin ky}{\sqrt{t\_3 + ky \cdot ky}} \cdot \sin th\\

\mathbf{elif}\;t\_4 \leq 0.995:\\
\;\;\;\;t\_5\\

\mathbf{elif}\;t\_4 \leq 1:\\
\;\;\;\;t\_2\\

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


\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 or 0.994999999999999996 < (/.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 89.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 \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. unpow2N/A

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\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.149999999999999994 or 4.00000000000000015e-10 < (/.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.994999999999999996

    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-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-sin.f64N/A

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
      10. unpow2N/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 \]
      11. 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 \]
      12. 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 \]
      13. 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 \]
      14. 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 \]
      15. 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 \]
      16. 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 \]
      17. 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 \]
    4. Applied rewrites99.4%

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

      \[\leadsto \frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \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}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \cdot \color{blue}{\left(\left(1 + \frac{-1}{6} \cdot {th}^{2}\right) \cdot th\right)} \]
      2. lower-*.f64N/A

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

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

        \[\leadsto \frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \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}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \cdot \left(\color{blue}{\mathsf{fma}\left({th}^{2}, \frac{-1}{6}, 1\right)} \cdot th\right) \]
      6. unpow2N/A

        \[\leadsto \frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \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}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \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}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \cdot \color{blue}{\left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)} \]

    if -0.149999999999999994 < (/.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.00000000000000015e-10

    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.5

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

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

    1. Initial program 2.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. *-commutativeN/A

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

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

        \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
      5. un-div-invN/A

        \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
      6. div-invN/A

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -1:\\ \;\;\;\;\frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \sin th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -0.15:\\ \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\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 4 \cdot 10^{-10}:\\ \;\;\;\;\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.995:\\ \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\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 1:\\ \;\;\;\;\frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{{ky}^{-1}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 82.2% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\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)\\ t_2 := {\sin ky}^{2}\\ t_3 := \frac{\sin ky}{\sqrt{kx \cdot kx + t\_2}} \cdot \sin th\\ t_4 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + t\_2}}\\ t_5 := \frac{\frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{{ky}^{-1}}\\ \mathbf{if}\;t\_4 \leq -1:\\ \;\;\;\;t\_3\\ \mathbf{elif}\;t\_4 \leq -0.15:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_4 \leq 4 \cdot 10^{-10}:\\ \;\;\;\;t\_5\\ \mathbf{elif}\;t\_4 \leq 0.995:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_4 \leq 1:\\ \;\;\;\;t\_3\\ \mathbf{else}:\\ \;\;\;\;t\_5\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1
         (*
          (/
           (sin ky)
           (/
            (sqrt
             (fma
              (- 1.0 (cos (* ky 2.0)))
              2.0
              (* 2.0 (- 1.0 (cos (* 2.0 kx))))))
            2.0))
          (* (fma (* th th) -0.16666666666666666 1.0) th)))
        (t_2 (pow (sin ky) 2.0))
        (t_3 (* (/ (sin ky) (sqrt (+ (* kx kx) t_2))) (sin th)))
        (t_4 (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) t_2))))
        (t_5 (/ (/ (sin th) (hypot (sin ky) (sin kx))) (pow ky -1.0))))
   (if (<= t_4 -1.0)
     t_3
     (if (<= t_4 -0.15)
       t_1
       (if (<= t_4 4e-10)
         t_5
         (if (<= t_4 0.995) t_1 (if (<= t_4 1.0) t_3 t_5)))))))
double code(double kx, double ky, double th) {
	double t_1 = (sin(ky) / (sqrt(fma((1.0 - cos((ky * 2.0))), 2.0, (2.0 * (1.0 - cos((2.0 * kx)))))) / 2.0)) * (fma((th * th), -0.16666666666666666, 1.0) * th);
	double t_2 = pow(sin(ky), 2.0);
	double t_3 = (sin(ky) / sqrt(((kx * kx) + t_2))) * sin(th);
	double t_4 = sin(ky) / sqrt((pow(sin(kx), 2.0) + t_2));
	double t_5 = (sin(th) / hypot(sin(ky), sin(kx))) / pow(ky, -1.0);
	double tmp;
	if (t_4 <= -1.0) {
		tmp = t_3;
	} else if (t_4 <= -0.15) {
		tmp = t_1;
	} else if (t_4 <= 4e-10) {
		tmp = t_5;
	} else if (t_4 <= 0.995) {
		tmp = t_1;
	} else if (t_4 <= 1.0) {
		tmp = t_3;
	} else {
		tmp = t_5;
	}
	return tmp;
}
function code(kx, ky, th)
	t_1 = Float64(Float64(sin(ky) / Float64(sqrt(fma(Float64(1.0 - cos(Float64(ky * 2.0))), 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))
	t_2 = sin(ky) ^ 2.0
	t_3 = Float64(Float64(sin(ky) / sqrt(Float64(Float64(kx * kx) + t_2))) * sin(th))
	t_4 = Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + t_2)))
	t_5 = Float64(Float64(sin(th) / hypot(sin(ky), sin(kx))) / (ky ^ -1.0))
	tmp = 0.0
	if (t_4 <= -1.0)
		tmp = t_3;
	elseif (t_4 <= -0.15)
		tmp = t_1;
	elseif (t_4 <= 4e-10)
		tmp = t_5;
	elseif (t_4 <= 0.995)
		tmp = t_1;
	elseif (t_4 <= 1.0)
		tmp = t_3;
	else
		tmp = t_5;
	end
	return tmp
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[(N[(N[Sin[ky], $MachinePrecision] / N[(N[Sqrt[N[(N[(1.0 - N[Cos[N[(ky * 2.0), $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]}, Block[{t$95$2 = N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$3 = N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(kx * kx), $MachinePrecision] + t$95$2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + t$95$2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$5 = N[(N[(N[Sin[th], $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] / N[Power[ky, -1.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$4, -1.0], t$95$3, If[LessEqual[t$95$4, -0.15], t$95$1, If[LessEqual[t$95$4, 4e-10], t$95$5, If[LessEqual[t$95$4, 0.995], t$95$1, If[LessEqual[t$95$4, 1.0], t$95$3, t$95$5]]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\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)\\
t_2 := {\sin ky}^{2}\\
t_3 := \frac{\sin ky}{\sqrt{kx \cdot kx + t\_2}} \cdot \sin th\\
t_4 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + t\_2}}\\
t_5 := \frac{\frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{{ky}^{-1}}\\
\mathbf{if}\;t\_4 \leq -1:\\
\;\;\;\;t\_3\\

\mathbf{elif}\;t\_4 \leq -0.15:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_4 \leq 4 \cdot 10^{-10}:\\
\;\;\;\;t\_5\\

\mathbf{elif}\;t\_4 \leq 0.995:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_4 \leq 1:\\
\;\;\;\;t\_3\\

\mathbf{else}:\\
\;\;\;\;t\_5\\


\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))))) < -1 or 0.994999999999999996 < (/.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 89.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 \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. unpow2N/A

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\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.149999999999999994 or 4.00000000000000015e-10 < (/.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.994999999999999996

    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-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-sin.f64N/A

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
      10. unpow2N/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 \]
      11. 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 \]
      12. 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 \]
      13. 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 \]
      14. 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 \]
      15. 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 \]
      16. 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 \]
      17. 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 \]
    4. Applied rewrites99.4%

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

      \[\leadsto \frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \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}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \cdot \color{blue}{\left(\left(1 + \frac{-1}{6} \cdot {th}^{2}\right) \cdot th\right)} \]
      2. lower-*.f64N/A

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

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

        \[\leadsto \frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \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}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \cdot \left(\color{blue}{\mathsf{fma}\left({th}^{2}, \frac{-1}{6}, 1\right)} \cdot th\right) \]
      6. unpow2N/A

        \[\leadsto \frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \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}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \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}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \cdot \color{blue}{\left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)} \]

    if -0.149999999999999994 < (/.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.00000000000000015e-10 or 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)))))

    1. Initial program 90.9%

      \[\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. *-commutativeN/A

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

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

        \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
      5. un-div-invN/A

        \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
      6. div-invN/A

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -1:\\ \;\;\;\;\frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \sin th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -0.15:\\ \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\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 4 \cdot 10^{-10}:\\ \;\;\;\;\frac{\frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{{ky}^{-1}}\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.995:\\ \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\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 1:\\ \;\;\;\;\frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{{ky}^{-1}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 77.8% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{\frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{{ky}^{-1}}\\ t_2 := {\sin ky}^{2}\\ t_3 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + t\_2}}\\ t_4 := \frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\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{if}\;t\_3 \leq -1:\\ \;\;\;\;\frac{\sin ky}{\sqrt{kx \cdot kx + \left(0.5 - 0.5 \cdot \cos \left(2 \cdot ky\right)\right)}} \cdot \sin th\\ \mathbf{elif}\;t\_3 \leq -0.15:\\ \;\;\;\;t\_4\\ \mathbf{elif}\;t\_3 \leq 4 \cdot 10^{-10}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_3 \leq 0.995:\\ \;\;\;\;t\_4\\ \mathbf{elif}\;t\_3 \leq 1:\\ \;\;\;\;\frac{\sin th}{\mathsf{fma}\left(\frac{0.5}{t\_2}, kx \cdot kx, 1\right)}\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (/ (/ (sin th) (hypot (sin ky) (sin kx))) (pow ky -1.0)))
        (t_2 (pow (sin ky) 2.0))
        (t_3 (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) t_2))))
        (t_4
         (*
          (/
           (sin ky)
           (/
            (sqrt
             (fma
              (- 1.0 (cos (* ky 2.0)))
              2.0
              (* 2.0 (- 1.0 (cos (* 2.0 kx))))))
            2.0))
          (* (fma (* th th) -0.16666666666666666 1.0) th))))
   (if (<= t_3 -1.0)
     (*
      (/ (sin ky) (sqrt (+ (* kx kx) (- 0.5 (* 0.5 (cos (* 2.0 ky)))))))
      (sin th))
     (if (<= t_3 -0.15)
       t_4
       (if (<= t_3 4e-10)
         t_1
         (if (<= t_3 0.995)
           t_4
           (if (<= t_3 1.0)
             (/ (sin th) (fma (/ 0.5 t_2) (* kx kx) 1.0))
             t_1)))))))
double code(double kx, double ky, double th) {
	double t_1 = (sin(th) / hypot(sin(ky), sin(kx))) / pow(ky, -1.0);
	double t_2 = pow(sin(ky), 2.0);
	double t_3 = sin(ky) / sqrt((pow(sin(kx), 2.0) + t_2));
	double t_4 = (sin(ky) / (sqrt(fma((1.0 - cos((ky * 2.0))), 2.0, (2.0 * (1.0 - cos((2.0 * kx)))))) / 2.0)) * (fma((th * th), -0.16666666666666666, 1.0) * th);
	double tmp;
	if (t_3 <= -1.0) {
		tmp = (sin(ky) / sqrt(((kx * kx) + (0.5 - (0.5 * cos((2.0 * ky))))))) * sin(th);
	} else if (t_3 <= -0.15) {
		tmp = t_4;
	} else if (t_3 <= 4e-10) {
		tmp = t_1;
	} else if (t_3 <= 0.995) {
		tmp = t_4;
	} else if (t_3 <= 1.0) {
		tmp = sin(th) / fma((0.5 / t_2), (kx * kx), 1.0);
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(kx, ky, th)
	t_1 = Float64(Float64(sin(th) / hypot(sin(ky), sin(kx))) / (ky ^ -1.0))
	t_2 = sin(ky) ^ 2.0
	t_3 = Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + t_2)))
	t_4 = Float64(Float64(sin(ky) / Float64(sqrt(fma(Float64(1.0 - cos(Float64(ky * 2.0))), 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))
	tmp = 0.0
	if (t_3 <= -1.0)
		tmp = Float64(Float64(sin(ky) / sqrt(Float64(Float64(kx * kx) + Float64(0.5 - Float64(0.5 * cos(Float64(2.0 * ky))))))) * sin(th));
	elseif (t_3 <= -0.15)
		tmp = t_4;
	elseif (t_3 <= 4e-10)
		tmp = t_1;
	elseif (t_3 <= 0.995)
		tmp = t_4;
	elseif (t_3 <= 1.0)
		tmp = Float64(sin(th) / fma(Float64(0.5 / t_2), Float64(kx * kx), 1.0));
	else
		tmp = t_1;
	end
	return tmp
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[(N[(N[Sin[th], $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] / N[Power[ky, -1.0], $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]}, Block[{t$95$4 = N[(N[(N[Sin[ky], $MachinePrecision] / N[(N[Sqrt[N[(N[(1.0 - N[Cos[N[(ky * 2.0), $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, -1.0], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(kx * kx), $MachinePrecision] + N[(0.5 - N[(0.5 * N[Cos[N[(2.0 * ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, -0.15], t$95$4, If[LessEqual[t$95$3, 4e-10], t$95$1, If[LessEqual[t$95$3, 0.995], t$95$4, If[LessEqual[t$95$3, 1.0], N[(N[Sin[th], $MachinePrecision] / N[(N[(0.5 / t$95$2), $MachinePrecision] * N[(kx * kx), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \frac{\frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{{ky}^{-1}}\\
t_2 := {\sin ky}^{2}\\
t_3 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + t\_2}}\\
t_4 := \frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\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{if}\;t\_3 \leq -1:\\
\;\;\;\;\frac{\sin ky}{\sqrt{kx \cdot kx + \left(0.5 - 0.5 \cdot \cos \left(2 \cdot ky\right)\right)}} \cdot \sin th\\

\mathbf{elif}\;t\_3 \leq -0.15:\\
\;\;\;\;t\_4\\

\mathbf{elif}\;t\_3 \leq 4 \cdot 10^{-10}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_3 \leq 0.995:\\
\;\;\;\;t\_4\\

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

\mathbf{else}:\\
\;\;\;\;t\_1\\


\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 79.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 \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. unpow2N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + \color{blue}{\left(0.5 - 0.5 \cdot \cos \left(2 \cdot ky\right)\right)}}} \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.149999999999999994 or 4.00000000000000015e-10 < (/.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.994999999999999996

    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-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-sin.f64N/A

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
      10. unpow2N/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 \]
      11. 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 \]
      12. 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 \]
      13. 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 \]
      14. 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 \]
      15. 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 \]
      16. 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 \]
      17. 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 \]
    4. Applied rewrites99.4%

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

      \[\leadsto \frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \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}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \cdot \color{blue}{\left(\left(1 + \frac{-1}{6} \cdot {th}^{2}\right) \cdot th\right)} \]
      2. lower-*.f64N/A

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

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

        \[\leadsto \frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \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}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \cdot \left(\color{blue}{\mathsf{fma}\left({th}^{2}, \frac{-1}{6}, 1\right)} \cdot th\right) \]
      6. unpow2N/A

        \[\leadsto \frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \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}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \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}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \cdot \color{blue}{\left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)} \]

    if -0.149999999999999994 < (/.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.00000000000000015e-10 or 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)))))

    1. Initial program 90.9%

      \[\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. *-commutativeN/A

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

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

        \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
      5. un-div-invN/A

        \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
      6. div-invN/A

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

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

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

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

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

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

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

    if 0.994999999999999996 < (/.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 100.0%

      \[\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. *-commutativeN/A

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

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

        \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
      5. un-div-invN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin th}{\color{blue}{\frac{\frac{1}{2}}{{\sin ky}^{2}} \cdot {kx}^{2}} + 1} \]
      4. metadata-evalN/A

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -1:\\ \;\;\;\;\frac{\sin ky}{\sqrt{kx \cdot kx + \left(0.5 - 0.5 \cdot \cos \left(2 \cdot ky\right)\right)}} \cdot \sin th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -0.15:\\ \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\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 4 \cdot 10^{-10}:\\ \;\;\;\;\frac{\frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{{ky}^{-1}}\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.995:\\ \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\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 1:\\ \;\;\;\;\frac{\sin th}{\mathsf{fma}\left(\frac{0.5}{{\sin ky}^{2}}, kx \cdot kx, 1\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{{ky}^{-1}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 82.4% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{hypot}\left(\sin ky, \sin kx\right)\\ t_2 := \mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\\ t_3 := {\sin ky}^{2}\\ t_4 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + t\_3}}\\ t_5 := \frac{\sin th}{\frac{t\_1}{\mathsf{fma}\left(-0.16666666666666666, ky \cdot ky, 1\right) \cdot ky}}\\ \mathbf{if}\;t\_4 \leq -1:\\ \;\;\;\;\frac{\sin ky}{\sqrt{kx \cdot kx + t\_3}} \cdot \sin th\\ \mathbf{elif}\;t\_4 \leq -0.15:\\ \;\;\;\;\frac{t\_2}{\frac{t\_1}{\sin ky}}\\ \mathbf{elif}\;t\_4 \leq 4 \cdot 10^{-10}:\\ \;\;\;\;t\_5\\ \mathbf{elif}\;t\_4 \leq 0.995:\\ \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \cdot t\_2\\ \mathbf{elif}\;t\_4 \leq 1:\\ \;\;\;\;\frac{\sin ky}{\sqrt{\mathsf{fma}\left(-0.3333333333333333, kx \cdot kx, 1\right) \cdot \left(kx \cdot kx\right) + t\_3}} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;t\_5\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (hypot (sin ky) (sin kx)))
        (t_2 (* (fma (* th th) -0.16666666666666666 1.0) th))
        (t_3 (pow (sin ky) 2.0))
        (t_4 (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) t_3))))
        (t_5
         (/ (sin th) (/ t_1 (* (fma -0.16666666666666666 (* ky ky) 1.0) ky)))))
   (if (<= t_4 -1.0)
     (* (/ (sin ky) (sqrt (+ (* kx kx) t_3))) (sin th))
     (if (<= t_4 -0.15)
       (/ t_2 (/ t_1 (sin ky)))
       (if (<= t_4 4e-10)
         t_5
         (if (<= t_4 0.995)
           (*
            (/
             (sin ky)
             (/
              (sqrt
               (fma
                (- 1.0 (cos (* ky 2.0)))
                2.0
                (* 2.0 (- 1.0 (cos (* 2.0 kx))))))
              2.0))
            t_2)
           (if (<= t_4 1.0)
             (*
              (/
               (sin ky)
               (sqrt
                (+ (* (fma -0.3333333333333333 (* kx kx) 1.0) (* kx kx)) t_3)))
              (sin th))
             t_5)))))))
double code(double kx, double ky, double th) {
	double t_1 = hypot(sin(ky), sin(kx));
	double t_2 = fma((th * th), -0.16666666666666666, 1.0) * th;
	double t_3 = pow(sin(ky), 2.0);
	double t_4 = sin(ky) / sqrt((pow(sin(kx), 2.0) + t_3));
	double t_5 = sin(th) / (t_1 / (fma(-0.16666666666666666, (ky * ky), 1.0) * ky));
	double tmp;
	if (t_4 <= -1.0) {
		tmp = (sin(ky) / sqrt(((kx * kx) + t_3))) * sin(th);
	} else if (t_4 <= -0.15) {
		tmp = t_2 / (t_1 / sin(ky));
	} else if (t_4 <= 4e-10) {
		tmp = t_5;
	} else if (t_4 <= 0.995) {
		tmp = (sin(ky) / (sqrt(fma((1.0 - cos((ky * 2.0))), 2.0, (2.0 * (1.0 - cos((2.0 * kx)))))) / 2.0)) * t_2;
	} else if (t_4 <= 1.0) {
		tmp = (sin(ky) / sqrt(((fma(-0.3333333333333333, (kx * kx), 1.0) * (kx * kx)) + t_3))) * sin(th);
	} else {
		tmp = t_5;
	}
	return tmp;
}
function code(kx, ky, th)
	t_1 = hypot(sin(ky), sin(kx))
	t_2 = Float64(fma(Float64(th * th), -0.16666666666666666, 1.0) * th)
	t_3 = sin(ky) ^ 2.0
	t_4 = Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + t_3)))
	t_5 = Float64(sin(th) / Float64(t_1 / Float64(fma(-0.16666666666666666, Float64(ky * ky), 1.0) * ky)))
	tmp = 0.0
	if (t_4 <= -1.0)
		tmp = Float64(Float64(sin(ky) / sqrt(Float64(Float64(kx * kx) + t_3))) * sin(th));
	elseif (t_4 <= -0.15)
		tmp = Float64(t_2 / Float64(t_1 / sin(ky)));
	elseif (t_4 <= 4e-10)
		tmp = t_5;
	elseif (t_4 <= 0.995)
		tmp = Float64(Float64(sin(ky) / Float64(sqrt(fma(Float64(1.0 - cos(Float64(ky * 2.0))), 2.0, Float64(2.0 * Float64(1.0 - cos(Float64(2.0 * kx)))))) / 2.0)) * t_2);
	elseif (t_4 <= 1.0)
		tmp = Float64(Float64(sin(ky) / sqrt(Float64(Float64(fma(-0.3333333333333333, Float64(kx * kx), 1.0) * Float64(kx * kx)) + t_3))) * sin(th));
	else
		tmp = t_5;
	end
	return tmp
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(th * th), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * th), $MachinePrecision]}, Block[{t$95$3 = N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$4 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + t$95$3), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$5 = N[(N[Sin[th], $MachinePrecision] / N[(t$95$1 / N[(N[(-0.16666666666666666 * N[(ky * ky), $MachinePrecision] + 1.0), $MachinePrecision] * ky), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$4, -1.0], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(kx * kx), $MachinePrecision] + t$95$3), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$4, -0.15], N[(t$95$2 / N[(t$95$1 / N[Sin[ky], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$4, 4e-10], t$95$5, If[LessEqual[t$95$4, 0.995], N[(N[(N[Sin[ky], $MachinePrecision] / N[(N[Sqrt[N[(N[(1.0 - N[Cos[N[(ky * 2.0), $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] * t$95$2), $MachinePrecision], If[LessEqual[t$95$4, 1.0], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(N[(-0.3333333333333333 * N[(kx * kx), $MachinePrecision] + 1.0), $MachinePrecision] * N[(kx * kx), $MachinePrecision]), $MachinePrecision] + t$95$3), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], t$95$5]]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \mathsf{hypot}\left(\sin ky, \sin kx\right)\\
t_2 := \mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\\
t_3 := {\sin ky}^{2}\\
t_4 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + t\_3}}\\
t_5 := \frac{\sin th}{\frac{t\_1}{\mathsf{fma}\left(-0.16666666666666666, ky \cdot ky, 1\right) \cdot ky}}\\
\mathbf{if}\;t\_4 \leq -1:\\
\;\;\;\;\frac{\sin ky}{\sqrt{kx \cdot kx + t\_3}} \cdot \sin th\\

\mathbf{elif}\;t\_4 \leq -0.15:\\
\;\;\;\;\frac{t\_2}{\frac{t\_1}{\sin ky}}\\

\mathbf{elif}\;t\_4 \leq 4 \cdot 10^{-10}:\\
\;\;\;\;t\_5\\

\mathbf{elif}\;t\_4 \leq 0.995:\\
\;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \cdot t\_2\\

\mathbf{elif}\;t\_4 \leq 1:\\
\;\;\;\;\frac{\sin ky}{\sqrt{\mathsf{fma}\left(-0.3333333333333333, kx \cdot kx, 1\right) \cdot \left(kx \cdot kx\right) + t\_3}} \cdot \sin th\\

\mathbf{else}:\\
\;\;\;\;t\_5\\


\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 79.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 \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. unpow2N/A

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\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.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-*.f64N/A

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

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

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

        \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
      5. un-div-invN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.149999999999999994 < (/.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.00000000000000015e-10 or 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)))))

    1. Initial program 90.9%

      \[\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. *-commutativeN/A

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

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

        \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
      5. un-div-invN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.00000000000000015e-10 < (/.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.994999999999999996

    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-sin.f64N/A

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
      10. unpow2N/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 \]
      11. 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 \]
      12. 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 \]
      13. 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 \]
      14. 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 \]
      15. 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 \]
      16. 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 \]
      17. 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 \]
    4. Applied rewrites99.3%

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

      \[\leadsto \frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \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}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \cdot \color{blue}{\left(\left(1 + \frac{-1}{6} \cdot {th}^{2}\right) \cdot th\right)} \]
      2. lower-*.f64N/A

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

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

        \[\leadsto \frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \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}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \cdot \left(\color{blue}{\mathsf{fma}\left({th}^{2}, \frac{-1}{6}, 1\right)} \cdot th\right) \]
      6. unpow2N/A

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

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

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

    if 0.994999999999999996 < (/.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 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 \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. unpow2N/A

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\mathsf{fma}\left(-0.3333333333333333, kx \cdot kx, 1\right) \cdot \left(kx \cdot kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
  3. Recombined 5 regimes into one program.
  4. Add Preprocessing

Alternative 7: 82.4% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{hypot}\left(\sin ky, \sin kx\right)\\ t_2 := \mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\\ t_3 := {\sin ky}^{2}\\ t_4 := \frac{\sin ky}{\sqrt{kx \cdot kx + t\_3}} \cdot \sin th\\ t_5 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + t\_3}}\\ t_6 := \frac{\sin th}{\frac{t\_1}{\mathsf{fma}\left(-0.16666666666666666, ky \cdot ky, 1\right) \cdot ky}}\\ \mathbf{if}\;t\_5 \leq -1:\\ \;\;\;\;t\_4\\ \mathbf{elif}\;t\_5 \leq -0.15:\\ \;\;\;\;\frac{t\_2}{\frac{t\_1}{\sin ky}}\\ \mathbf{elif}\;t\_5 \leq 4 \cdot 10^{-10}:\\ \;\;\;\;t\_6\\ \mathbf{elif}\;t\_5 \leq 0.995:\\ \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \cdot t\_2\\ \mathbf{elif}\;t\_5 \leq 1:\\ \;\;\;\;t\_4\\ \mathbf{else}:\\ \;\;\;\;t\_6\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (hypot (sin ky) (sin kx)))
        (t_2 (* (fma (* th th) -0.16666666666666666 1.0) th))
        (t_3 (pow (sin ky) 2.0))
        (t_4 (* (/ (sin ky) (sqrt (+ (* kx kx) t_3))) (sin th)))
        (t_5 (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) t_3))))
        (t_6
         (/ (sin th) (/ t_1 (* (fma -0.16666666666666666 (* ky ky) 1.0) ky)))))
   (if (<= t_5 -1.0)
     t_4
     (if (<= t_5 -0.15)
       (/ t_2 (/ t_1 (sin ky)))
       (if (<= t_5 4e-10)
         t_6
         (if (<= t_5 0.995)
           (*
            (/
             (sin ky)
             (/
              (sqrt
               (fma
                (- 1.0 (cos (* ky 2.0)))
                2.0
                (* 2.0 (- 1.0 (cos (* 2.0 kx))))))
              2.0))
            t_2)
           (if (<= t_5 1.0) t_4 t_6)))))))
double code(double kx, double ky, double th) {
	double t_1 = hypot(sin(ky), sin(kx));
	double t_2 = fma((th * th), -0.16666666666666666, 1.0) * th;
	double t_3 = pow(sin(ky), 2.0);
	double t_4 = (sin(ky) / sqrt(((kx * kx) + t_3))) * sin(th);
	double t_5 = sin(ky) / sqrt((pow(sin(kx), 2.0) + t_3));
	double t_6 = sin(th) / (t_1 / (fma(-0.16666666666666666, (ky * ky), 1.0) * ky));
	double tmp;
	if (t_5 <= -1.0) {
		tmp = t_4;
	} else if (t_5 <= -0.15) {
		tmp = t_2 / (t_1 / sin(ky));
	} else if (t_5 <= 4e-10) {
		tmp = t_6;
	} else if (t_5 <= 0.995) {
		tmp = (sin(ky) / (sqrt(fma((1.0 - cos((ky * 2.0))), 2.0, (2.0 * (1.0 - cos((2.0 * kx)))))) / 2.0)) * t_2;
	} else if (t_5 <= 1.0) {
		tmp = t_4;
	} else {
		tmp = t_6;
	}
	return tmp;
}
function code(kx, ky, th)
	t_1 = hypot(sin(ky), sin(kx))
	t_2 = Float64(fma(Float64(th * th), -0.16666666666666666, 1.0) * th)
	t_3 = sin(ky) ^ 2.0
	t_4 = Float64(Float64(sin(ky) / sqrt(Float64(Float64(kx * kx) + t_3))) * sin(th))
	t_5 = Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + t_3)))
	t_6 = Float64(sin(th) / Float64(t_1 / Float64(fma(-0.16666666666666666, Float64(ky * ky), 1.0) * ky)))
	tmp = 0.0
	if (t_5 <= -1.0)
		tmp = t_4;
	elseif (t_5 <= -0.15)
		tmp = Float64(t_2 / Float64(t_1 / sin(ky)));
	elseif (t_5 <= 4e-10)
		tmp = t_6;
	elseif (t_5 <= 0.995)
		tmp = Float64(Float64(sin(ky) / Float64(sqrt(fma(Float64(1.0 - cos(Float64(ky * 2.0))), 2.0, Float64(2.0 * Float64(1.0 - cos(Float64(2.0 * kx)))))) / 2.0)) * t_2);
	elseif (t_5 <= 1.0)
		tmp = t_4;
	else
		tmp = t_6;
	end
	return tmp
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(th * th), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * th), $MachinePrecision]}, Block[{t$95$3 = N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$4 = N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(kx * kx), $MachinePrecision] + t$95$3), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$5 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + t$95$3), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$6 = N[(N[Sin[th], $MachinePrecision] / N[(t$95$1 / N[(N[(-0.16666666666666666 * N[(ky * ky), $MachinePrecision] + 1.0), $MachinePrecision] * ky), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$5, -1.0], t$95$4, If[LessEqual[t$95$5, -0.15], N[(t$95$2 / N[(t$95$1 / N[Sin[ky], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$5, 4e-10], t$95$6, If[LessEqual[t$95$5, 0.995], N[(N[(N[Sin[ky], $MachinePrecision] / N[(N[Sqrt[N[(N[(1.0 - N[Cos[N[(ky * 2.0), $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] * t$95$2), $MachinePrecision], If[LessEqual[t$95$5, 1.0], t$95$4, t$95$6]]]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \mathsf{hypot}\left(\sin ky, \sin kx\right)\\
t_2 := \mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\\
t_3 := {\sin ky}^{2}\\
t_4 := \frac{\sin ky}{\sqrt{kx \cdot kx + t\_3}} \cdot \sin th\\
t_5 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + t\_3}}\\
t_6 := \frac{\sin th}{\frac{t\_1}{\mathsf{fma}\left(-0.16666666666666666, ky \cdot ky, 1\right) \cdot ky}}\\
\mathbf{if}\;t\_5 \leq -1:\\
\;\;\;\;t\_4\\

\mathbf{elif}\;t\_5 \leq -0.15:\\
\;\;\;\;\frac{t\_2}{\frac{t\_1}{\sin ky}}\\

\mathbf{elif}\;t\_5 \leq 4 \cdot 10^{-10}:\\
\;\;\;\;t\_6\\

\mathbf{elif}\;t\_5 \leq 0.995:\\
\;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \cdot t\_2\\

\mathbf{elif}\;t\_5 \leq 1:\\
\;\;\;\;t\_4\\

\mathbf{else}:\\
\;\;\;\;t\_6\\


\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 or 0.994999999999999996 < (/.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 89.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 \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. unpow2N/A

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\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.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-*.f64N/A

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

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

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

        \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
      5. un-div-invN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.149999999999999994 < (/.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.00000000000000015e-10 or 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)))))

    1. Initial program 90.9%

      \[\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. *-commutativeN/A

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

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

        \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
      5. un-div-invN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.00000000000000015e-10 < (/.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.994999999999999996

    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-sin.f64N/A

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
      10. unpow2N/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 \]
      11. 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 \]
      12. 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 \]
      13. 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 \]
      14. 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 \]
      15. 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 \]
      16. 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 \]
      17. 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 \]
    4. Applied rewrites99.3%

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

      \[\leadsto \frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \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}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \cdot \color{blue}{\left(\left(1 + \frac{-1}{6} \cdot {th}^{2}\right) \cdot th\right)} \]
      2. lower-*.f64N/A

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

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

        \[\leadsto \frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \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}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \cdot \left(\color{blue}{\mathsf{fma}\left({th}^{2}, \frac{-1}{6}, 1\right)} \cdot th\right) \]
      6. unpow2N/A

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

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

      \[\leadsto \frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \cdot \color{blue}{\left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)} \]
  3. Recombined 4 regimes into one program.
  4. Add Preprocessing

Alternative 8: 66.6% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\ t_2 := 1 - \cos \left(2 \cdot kx\right)\\ t_3 := \frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot t\_2\right)}}{2}} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)\\ \mathbf{if}\;t\_1 \leq -1:\\ \;\;\;\;\frac{\sin ky}{\sqrt{kx \cdot kx + \left(0.5 - 0.5 \cdot \cos \left(2 \cdot ky\right)\right)}} \cdot \sin th\\ \mathbf{elif}\;t\_1 \leq -0.41:\\ \;\;\;\;t\_3\\ \mathbf{elif}\;t\_1 \leq 10^{-178}:\\ \;\;\;\;\frac{\sin ky}{\frac{\sqrt{t\_2 \cdot 2}}{2}} \cdot \sin th\\ \mathbf{elif}\;t\_1 \leq 4 \cdot 10^{-10}:\\ \;\;\;\;\frac{\sin th}{\frac{\sin kx}{ky}}\\ \mathbf{elif}\;t\_1 \leq 0.995:\\ \;\;\;\;t\_3\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th}{\mathsf{fma}\left(\frac{0.5 \cdot kx}{\sin ky}, \frac{kx}{\sin ky}, 1\right)}\\ \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)))))
        (t_2 (- 1.0 (cos (* 2.0 kx))))
        (t_3
         (*
          (/
           (sin ky)
           (/ (sqrt (fma (- 1.0 (cos (* ky 2.0))) 2.0 (* 2.0 t_2))) 2.0))
          (* (fma (* th th) -0.16666666666666666 1.0) th))))
   (if (<= t_1 -1.0)
     (*
      (/ (sin ky) (sqrt (+ (* kx kx) (- 0.5 (* 0.5 (cos (* 2.0 ky)))))))
      (sin th))
     (if (<= t_1 -0.41)
       t_3
       (if (<= t_1 1e-178)
         (* (/ (sin ky) (/ (sqrt (* t_2 2.0)) 2.0)) (sin th))
         (if (<= t_1 4e-10)
           (/ (sin th) (/ (sin kx) ky))
           (if (<= t_1 0.995)
             t_3
             (/
              (sin th)
              (fma (/ (* 0.5 kx) (sin ky)) (/ kx (sin ky)) 1.0)))))))))
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 t_2 = 1.0 - cos((2.0 * kx));
	double t_3 = (sin(ky) / (sqrt(fma((1.0 - cos((ky * 2.0))), 2.0, (2.0 * t_2))) / 2.0)) * (fma((th * th), -0.16666666666666666, 1.0) * th);
	double tmp;
	if (t_1 <= -1.0) {
		tmp = (sin(ky) / sqrt(((kx * kx) + (0.5 - (0.5 * cos((2.0 * ky))))))) * sin(th);
	} else if (t_1 <= -0.41) {
		tmp = t_3;
	} else if (t_1 <= 1e-178) {
		tmp = (sin(ky) / (sqrt((t_2 * 2.0)) / 2.0)) * sin(th);
	} else if (t_1 <= 4e-10) {
		tmp = sin(th) / (sin(kx) / ky);
	} else if (t_1 <= 0.995) {
		tmp = t_3;
	} else {
		tmp = sin(th) / fma(((0.5 * kx) / sin(ky)), (kx / sin(ky)), 1.0);
	}
	return tmp;
}
function code(kx, ky, th)
	t_1 = Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0))))
	t_2 = Float64(1.0 - cos(Float64(2.0 * kx)))
	t_3 = Float64(Float64(sin(ky) / Float64(sqrt(fma(Float64(1.0 - cos(Float64(ky * 2.0))), 2.0, Float64(2.0 * t_2))) / 2.0)) * Float64(fma(Float64(th * th), -0.16666666666666666, 1.0) * th))
	tmp = 0.0
	if (t_1 <= -1.0)
		tmp = Float64(Float64(sin(ky) / sqrt(Float64(Float64(kx * kx) + Float64(0.5 - Float64(0.5 * cos(Float64(2.0 * ky))))))) * sin(th));
	elseif (t_1 <= -0.41)
		tmp = t_3;
	elseif (t_1 <= 1e-178)
		tmp = Float64(Float64(sin(ky) / Float64(sqrt(Float64(t_2 * 2.0)) / 2.0)) * sin(th));
	elseif (t_1 <= 4e-10)
		tmp = Float64(sin(th) / Float64(sin(kx) / ky));
	elseif (t_1 <= 0.995)
		tmp = t_3;
	else
		tmp = Float64(sin(th) / fma(Float64(Float64(0.5 * kx) / sin(ky)), Float64(kx / sin(ky)), 1.0));
	end
	return 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]}, Block[{t$95$2 = N[(1.0 - N[Cos[N[(2.0 * kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[(N[Sin[ky], $MachinePrecision] / N[(N[Sqrt[N[(N[(1.0 - N[Cos[N[(ky * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 2.0 + N[(2.0 * t$95$2), $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$1, -1.0], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(kx * kx), $MachinePrecision] + N[(0.5 - N[(0.5 * N[Cos[N[(2.0 * ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, -0.41], t$95$3, If[LessEqual[t$95$1, 1e-178], N[(N[(N[Sin[ky], $MachinePrecision] / N[(N[Sqrt[N[(t$95$2 * 2.0), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 4e-10], N[(N[Sin[th], $MachinePrecision] / N[(N[Sin[kx], $MachinePrecision] / ky), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 0.995], t$95$3, N[(N[Sin[th], $MachinePrecision] / N[(N[(N[(0.5 * kx), $MachinePrecision] / N[Sin[ky], $MachinePrecision]), $MachinePrecision] * N[(kx / N[Sin[ky], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\
t_2 := 1 - \cos \left(2 \cdot kx\right)\\
t_3 := \frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot t\_2\right)}}{2}} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)\\
\mathbf{if}\;t\_1 \leq -1:\\
\;\;\;\;\frac{\sin ky}{\sqrt{kx \cdot kx + \left(0.5 - 0.5 \cdot \cos \left(2 \cdot ky\right)\right)}} \cdot \sin th\\

\mathbf{elif}\;t\_1 \leq -0.41:\\
\;\;\;\;t\_3\\

\mathbf{elif}\;t\_1 \leq 10^{-178}:\\
\;\;\;\;\frac{\sin ky}{\frac{\sqrt{t\_2 \cdot 2}}{2}} \cdot \sin th\\

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

\mathbf{elif}\;t\_1 \leq 0.995:\\
\;\;\;\;t\_3\\

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


\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 79.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 \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. unpow2N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + \color{blue}{\left(0.5 - 0.5 \cdot \cos \left(2 \cdot ky\right)\right)}}} \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.409999999999999976 or 4.00000000000000015e-10 < (/.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.994999999999999996

    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-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-sin.f64N/A

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
      10. unpow2N/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 \]
      11. 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 \]
      12. 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 \]
      13. 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 \]
      14. 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 \]
      15. 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 \]
      16. 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 \]
      17. 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 \]
    4. Applied rewrites99.4%

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

      \[\leadsto \frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \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}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \cdot \color{blue}{\left(\left(1 + \frac{-1}{6} \cdot {th}^{2}\right) \cdot th\right)} \]
      2. lower-*.f64N/A

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

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

        \[\leadsto \frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \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}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \cdot \left(\color{blue}{\mathsf{fma}\left({th}^{2}, \frac{-1}{6}, 1\right)} \cdot th\right) \]
      6. unpow2N/A

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

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

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

    if -0.409999999999999976 < (/.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))))) < 9.9999999999999995e-179

    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-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-sin.f64N/A

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
      10. unpow2N/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 \]
      11. 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 \]
      12. 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 \]
      13. 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 \]
      14. 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 \]
      15. 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 \]
      16. 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 \]
      17. 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 \]
    4. Applied rewrites79.3%

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

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

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

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

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

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

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

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

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

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

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

      if 9.9999999999999995e-179 < (/.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.00000000000000015e-10

      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-*.f64N/A

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

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

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

          \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
        5. un-div-invN/A

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sin kx}{ky}}} \]
      6. Step-by-step derivation
        1. lower-/.f64N/A

          \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sin kx}{ky}}} \]
        2. lower-sin.f6454.7

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

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

      if 0.994999999999999996 < (/.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 83.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. *-commutativeN/A

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

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

          \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
        5. un-div-invN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \frac{\sin th}{\color{blue}{\frac{\frac{1}{2}}{{\sin ky}^{2}} \cdot {kx}^{2}} + 1} \]
        4. metadata-evalN/A

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \frac{\sin th}{\mathsf{fma}\left(\frac{0.5 \cdot kx}{\sin ky}, \color{blue}{\frac{kx}{\sin ky}}, 1\right)} \]
      9. Recombined 5 regimes into one program.
      10. Add Preprocessing

      Alternative 9: 66.7% accurate, 0.2× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\ t_2 := \cos \left(2 \cdot kx\right)\\ t_3 := \cos \left(2 \cdot ky\right)\\ t_4 := \left(2 \cdot \left(\sin ky \cdot th\right)\right) \cdot \sqrt{\frac{0.5}{1 - \left(t\_2 - \left(1 - t\_3\right)\right)}}\\ \mathbf{if}\;t\_1 \leq -1:\\ \;\;\;\;\frac{\sin ky}{\sqrt{kx \cdot kx + \left(0.5 - 0.5 \cdot t\_3\right)}} \cdot \sin th\\ \mathbf{elif}\;t\_1 \leq -0.41:\\ \;\;\;\;t\_4\\ \mathbf{elif}\;t\_1 \leq 10^{-178}:\\ \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\left(1 - t\_2\right) \cdot 2}}{2}} \cdot \sin th\\ \mathbf{elif}\;t\_1 \leq 2 \cdot 10^{-11}:\\ \;\;\;\;\frac{\sin th}{\frac{\sin kx}{ky}}\\ \mathbf{elif}\;t\_1 \leq 0.995:\\ \;\;\;\;t\_4\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th}{\mathsf{fma}\left(\frac{0.5 \cdot kx}{\sin ky}, \frac{kx}{\sin ky}, 1\right)}\\ \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)))))
              (t_2 (cos (* 2.0 kx)))
              (t_3 (cos (* 2.0 ky)))
              (t_4
               (*
                (* 2.0 (* (sin ky) th))
                (sqrt (/ 0.5 (- 1.0 (- t_2 (- 1.0 t_3))))))))
         (if (<= t_1 -1.0)
           (* (/ (sin ky) (sqrt (+ (* kx kx) (- 0.5 (* 0.5 t_3))))) (sin th))
           (if (<= t_1 -0.41)
             t_4
             (if (<= t_1 1e-178)
               (* (/ (sin ky) (/ (sqrt (* (- 1.0 t_2) 2.0)) 2.0)) (sin th))
               (if (<= t_1 2e-11)
                 (/ (sin th) (/ (sin kx) ky))
                 (if (<= t_1 0.995)
                   t_4
                   (/
                    (sin th)
                    (fma (/ (* 0.5 kx) (sin ky)) (/ kx (sin ky)) 1.0)))))))))
      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 t_2 = cos((2.0 * kx));
      	double t_3 = cos((2.0 * ky));
      	double t_4 = (2.0 * (sin(ky) * th)) * sqrt((0.5 / (1.0 - (t_2 - (1.0 - t_3)))));
      	double tmp;
      	if (t_1 <= -1.0) {
      		tmp = (sin(ky) / sqrt(((kx * kx) + (0.5 - (0.5 * t_3))))) * sin(th);
      	} else if (t_1 <= -0.41) {
      		tmp = t_4;
      	} else if (t_1 <= 1e-178) {
      		tmp = (sin(ky) / (sqrt(((1.0 - t_2) * 2.0)) / 2.0)) * sin(th);
      	} else if (t_1 <= 2e-11) {
      		tmp = sin(th) / (sin(kx) / ky);
      	} else if (t_1 <= 0.995) {
      		tmp = t_4;
      	} else {
      		tmp = sin(th) / fma(((0.5 * kx) / sin(ky)), (kx / sin(ky)), 1.0);
      	}
      	return tmp;
      }
      
      function code(kx, ky, th)
      	t_1 = Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0))))
      	t_2 = cos(Float64(2.0 * kx))
      	t_3 = cos(Float64(2.0 * ky))
      	t_4 = Float64(Float64(2.0 * Float64(sin(ky) * th)) * sqrt(Float64(0.5 / Float64(1.0 - Float64(t_2 - Float64(1.0 - t_3))))))
      	tmp = 0.0
      	if (t_1 <= -1.0)
      		tmp = Float64(Float64(sin(ky) / sqrt(Float64(Float64(kx * kx) + Float64(0.5 - Float64(0.5 * t_3))))) * sin(th));
      	elseif (t_1 <= -0.41)
      		tmp = t_4;
      	elseif (t_1 <= 1e-178)
      		tmp = Float64(Float64(sin(ky) / Float64(sqrt(Float64(Float64(1.0 - t_2) * 2.0)) / 2.0)) * sin(th));
      	elseif (t_1 <= 2e-11)
      		tmp = Float64(sin(th) / Float64(sin(kx) / ky));
      	elseif (t_1 <= 0.995)
      		tmp = t_4;
      	else
      		tmp = Float64(sin(th) / fma(Float64(Float64(0.5 * kx) / sin(ky)), Float64(kx / sin(ky)), 1.0));
      	end
      	return 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]}, Block[{t$95$2 = N[Cos[N[(2.0 * kx), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[Cos[N[(2.0 * ky), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$4 = N[(N[(2.0 * N[(N[Sin[ky], $MachinePrecision] * th), $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(0.5 / N[(1.0 - N[(t$95$2 - N[(1.0 - t$95$3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -1.0], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(kx * kx), $MachinePrecision] + N[(0.5 - N[(0.5 * t$95$3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, -0.41], t$95$4, If[LessEqual[t$95$1, 1e-178], N[(N[(N[Sin[ky], $MachinePrecision] / N[(N[Sqrt[N[(N[(1.0 - t$95$2), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2e-11], N[(N[Sin[th], $MachinePrecision] / N[(N[Sin[kx], $MachinePrecision] / ky), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 0.995], t$95$4, N[(N[Sin[th], $MachinePrecision] / N[(N[(N[(0.5 * kx), $MachinePrecision] / N[Sin[ky], $MachinePrecision]), $MachinePrecision] * N[(kx / N[Sin[ky], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]]]]]]]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\
      t_2 := \cos \left(2 \cdot kx\right)\\
      t_3 := \cos \left(2 \cdot ky\right)\\
      t_4 := \left(2 \cdot \left(\sin ky \cdot th\right)\right) \cdot \sqrt{\frac{0.5}{1 - \left(t\_2 - \left(1 - t\_3\right)\right)}}\\
      \mathbf{if}\;t\_1 \leq -1:\\
      \;\;\;\;\frac{\sin ky}{\sqrt{kx \cdot kx + \left(0.5 - 0.5 \cdot t\_3\right)}} \cdot \sin th\\
      
      \mathbf{elif}\;t\_1 \leq -0.41:\\
      \;\;\;\;t\_4\\
      
      \mathbf{elif}\;t\_1 \leq 10^{-178}:\\
      \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\left(1 - t\_2\right) \cdot 2}}{2}} \cdot \sin th\\
      
      \mathbf{elif}\;t\_1 \leq 2 \cdot 10^{-11}:\\
      \;\;\;\;\frac{\sin th}{\frac{\sin kx}{ky}}\\
      
      \mathbf{elif}\;t\_1 \leq 0.995:\\
      \;\;\;\;t\_4\\
      
      \mathbf{else}:\\
      \;\;\;\;\frac{\sin th}{\mathsf{fma}\left(\frac{0.5 \cdot kx}{\sin ky}, \frac{kx}{\sin ky}, 1\right)}\\
      
      
      \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 79.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 \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
        4. Step-by-step derivation
          1. unpow2N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + \color{blue}{\left(0.5 - 0.5 \cdot \cos \left(2 \cdot ky\right)\right)}}} \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.409999999999999976 or 1.99999999999999988e-11 < (/.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.994999999999999996

        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-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-sin.f64N/A

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

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

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

            \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
          10. unpow2N/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 \]
          11. 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 \]
          12. 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 \]
          13. 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 \]
          14. 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 \]
          15. 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 \]
          16. 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 \]
          17. 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 \]
        4. Applied rewrites99.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        if -0.409999999999999976 < (/.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))))) < 9.9999999999999995e-179

        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-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-sin.f64N/A

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

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

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

            \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
          10. unpow2N/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 \]
          11. 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 \]
          12. 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 \]
          13. 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 \]
          14. 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 \]
          15. 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 \]
          16. 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 \]
          17. 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 \]
        4. Applied rewrites79.3%

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

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

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

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

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

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

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

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

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

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

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

          if 9.9999999999999995e-179 < (/.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.99999999999999988e-11

          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-*.f64N/A

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

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

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

              \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
            5. un-div-invN/A

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sin kx}{ky}}} \]
          6. Step-by-step derivation
            1. lower-/.f64N/A

              \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sin kx}{ky}}} \]
            2. lower-sin.f6453.3

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

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

          if 0.994999999999999996 < (/.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 83.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. *-commutativeN/A

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

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

              \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
            5. un-div-invN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto \frac{\sin th}{\color{blue}{\frac{\frac{1}{2}}{{\sin ky}^{2}} \cdot {kx}^{2}} + 1} \]
            4. metadata-evalN/A

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto \frac{\sin th}{\mathsf{fma}\left(\frac{0.5 \cdot kx}{\sin ky}, \color{blue}{\frac{kx}{\sin ky}}, 1\right)} \]
          9. Recombined 5 regimes into one program.
          10. Add Preprocessing

          Alternative 10: 60.1% accurate, 0.3× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\ \mathbf{if}\;t\_1 \leq -0.7:\\ \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\left(1 - \cos \left(2 \cdot ky\right)\right) \cdot 2}}{2}} \cdot \sin th\\ \mathbf{elif}\;t\_1 \leq 10^{-178}:\\ \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\left(1 - \cos \left(2 \cdot kx\right)\right) \cdot 2}}{2}} \cdot \sin th\\ \mathbf{elif}\;t\_1 \leq 0.21:\\ \;\;\;\;\frac{\sin th}{\frac{\sin kx}{\sin ky}}\\ \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 -0.7)
               (* (/ (sin ky) (/ (sqrt (* (- 1.0 (cos (* 2.0 ky))) 2.0)) 2.0)) (sin th))
               (if (<= t_1 1e-178)
                 (*
                  (/ (sin ky) (/ (sqrt (* (- 1.0 (cos (* 2.0 kx))) 2.0)) 2.0))
                  (sin th))
                 (if (<= t_1 0.21) (/ (sin th) (/ (sin kx) (sin 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 <= -0.7) {
          		tmp = (sin(ky) / (sqrt(((1.0 - cos((2.0 * ky))) * 2.0)) / 2.0)) * sin(th);
          	} else if (t_1 <= 1e-178) {
          		tmp = (sin(ky) / (sqrt(((1.0 - cos((2.0 * kx))) * 2.0)) / 2.0)) * sin(th);
          	} else if (t_1 <= 0.21) {
          		tmp = sin(th) / (sin(kx) / sin(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 <= (-0.7d0)) then
                  tmp = (sin(ky) / (sqrt(((1.0d0 - cos((2.0d0 * ky))) * 2.0d0)) / 2.0d0)) * sin(th)
              else if (t_1 <= 1d-178) then
                  tmp = (sin(ky) / (sqrt(((1.0d0 - cos((2.0d0 * kx))) * 2.0d0)) / 2.0d0)) * sin(th)
              else if (t_1 <= 0.21d0) then
                  tmp = sin(th) / (sin(kx) / sin(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 <= -0.7) {
          		tmp = (Math.sin(ky) / (Math.sqrt(((1.0 - Math.cos((2.0 * ky))) * 2.0)) / 2.0)) * Math.sin(th);
          	} else if (t_1 <= 1e-178) {
          		tmp = (Math.sin(ky) / (Math.sqrt(((1.0 - Math.cos((2.0 * kx))) * 2.0)) / 2.0)) * Math.sin(th);
          	} else if (t_1 <= 0.21) {
          		tmp = Math.sin(th) / (Math.sin(kx) / Math.sin(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 <= -0.7:
          		tmp = (math.sin(ky) / (math.sqrt(((1.0 - math.cos((2.0 * ky))) * 2.0)) / 2.0)) * math.sin(th)
          	elif t_1 <= 1e-178:
          		tmp = (math.sin(ky) / (math.sqrt(((1.0 - math.cos((2.0 * kx))) * 2.0)) / 2.0)) * math.sin(th)
          	elif t_1 <= 0.21:
          		tmp = math.sin(th) / (math.sin(kx) / math.sin(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 <= -0.7)
          		tmp = Float64(Float64(sin(ky) / Float64(sqrt(Float64(Float64(1.0 - cos(Float64(2.0 * ky))) * 2.0)) / 2.0)) * sin(th));
          	elseif (t_1 <= 1e-178)
          		tmp = Float64(Float64(sin(ky) / Float64(sqrt(Float64(Float64(1.0 - cos(Float64(2.0 * kx))) * 2.0)) / 2.0)) * sin(th));
          	elseif (t_1 <= 0.21)
          		tmp = Float64(sin(th) / Float64(sin(kx) / sin(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 <= -0.7)
          		tmp = (sin(ky) / (sqrt(((1.0 - cos((2.0 * ky))) * 2.0)) / 2.0)) * sin(th);
          	elseif (t_1 <= 1e-178)
          		tmp = (sin(ky) / (sqrt(((1.0 - cos((2.0 * kx))) * 2.0)) / 2.0)) * sin(th);
          	elseif (t_1 <= 0.21)
          		tmp = sin(th) / (sin(kx) / sin(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, -0.7], N[(N[(N[Sin[ky], $MachinePrecision] / N[(N[Sqrt[N[(N[(1.0 - N[Cos[N[(2.0 * ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 1e-178], N[(N[(N[Sin[ky], $MachinePrecision] / N[(N[Sqrt[N[(N[(1.0 - N[Cos[N[(2.0 * kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 0.21], N[(N[Sin[th], $MachinePrecision] / N[(N[Sin[kx], $MachinePrecision] / N[Sin[ky], $MachinePrecision]), $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 -0.7:\\
          \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\left(1 - \cos \left(2 \cdot ky\right)\right) \cdot 2}}{2}} \cdot \sin th\\
          
          \mathbf{elif}\;t\_1 \leq 10^{-178}:\\
          \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\left(1 - \cos \left(2 \cdot kx\right)\right) \cdot 2}}{2}} \cdot \sin th\\
          
          \mathbf{elif}\;t\_1 \leq 0.21:\\
          \;\;\;\;\frac{\sin th}{\frac{\sin kx}{\sin ky}}\\
          
          \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))))) < -0.69999999999999996

            1. Initial program 84.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-sin.f64N/A

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

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

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

                \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
              10. unpow2N/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 \]
              11. 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 \]
              12. 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 \]
              13. 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 \]
              14. 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 \]
              15. 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 \]
              16. 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 \]
              17. 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 \]
            4. Applied rewrites61.0%

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

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

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

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

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

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

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

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

            if -0.69999999999999996 < (/.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))))) < 9.9999999999999995e-179

            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-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-sin.f64N/A

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

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

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

                \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
              10. unpow2N/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 \]
              11. 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 \]
              12. 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 \]
              13. 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 \]
              14. 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 \]
              15. 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 \]
              16. 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 \]
              17. 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 \]
            4. Applied rewrites81.0%

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

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

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

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

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

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

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

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

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

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

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

              if 9.9999999999999995e-179 < (/.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.209999999999999992

              1. Initial program 99.7%

                \[\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. *-commutativeN/A

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

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

                  \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                5. un-div-invN/A

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

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

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

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

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

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

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

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

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

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

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

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

                \[\leadsto \frac{\sin th}{\frac{\color{blue}{\sin kx}}{\sin ky}} \]
              6. Step-by-step derivation
                1. lower-sin.f6448.2

                  \[\leadsto \frac{\sin th}{\frac{\color{blue}{\sin kx}}{\sin ky}} \]
              7. Applied rewrites48.2%

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

              if 0.209999999999999992 < (/.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 89.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.f6463.6

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

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

              \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -0.7:\\ \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\left(1 - \cos \left(2 \cdot ky\right)\right) \cdot 2}}{2}} \cdot \sin th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 10^{-178}:\\ \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\left(1 - \cos \left(2 \cdot kx\right)\right) \cdot 2}}{2}} \cdot \sin th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.21:\\ \;\;\;\;\frac{\sin th}{\frac{\sin kx}{\sin ky}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
            11. Add Preprocessing

            Alternative 11: 59.6% accurate, 0.3× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\ \mathbf{if}\;t\_1 \leq -1:\\ \;\;\;\;\frac{\sin ky}{\sqrt{kx \cdot kx + \left(0.5 - 0.5 \cdot \cos \left(2 \cdot ky\right)\right)}} \cdot \sin th\\ \mathbf{elif}\;t\_1 \leq 10^{-178}:\\ \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\left(1 - \cos \left(2 \cdot kx\right)\right) \cdot 2}}{2}} \cdot \sin th\\ \mathbf{elif}\;t\_1 \leq 0.21:\\ \;\;\;\;\frac{\sin th}{\frac{\sin kx}{\sin ky}}\\ \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 -1.0)
                 (*
                  (/ (sin ky) (sqrt (+ (* kx kx) (- 0.5 (* 0.5 (cos (* 2.0 ky)))))))
                  (sin th))
                 (if (<= t_1 1e-178)
                   (*
                    (/ (sin ky) (/ (sqrt (* (- 1.0 (cos (* 2.0 kx))) 2.0)) 2.0))
                    (sin th))
                   (if (<= t_1 0.21) (/ (sin th) (/ (sin kx) (sin 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 <= -1.0) {
            		tmp = (sin(ky) / sqrt(((kx * kx) + (0.5 - (0.5 * cos((2.0 * ky))))))) * sin(th);
            	} else if (t_1 <= 1e-178) {
            		tmp = (sin(ky) / (sqrt(((1.0 - cos((2.0 * kx))) * 2.0)) / 2.0)) * sin(th);
            	} else if (t_1 <= 0.21) {
            		tmp = sin(th) / (sin(kx) / sin(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 <= (-1.0d0)) then
                    tmp = (sin(ky) / sqrt(((kx * kx) + (0.5d0 - (0.5d0 * cos((2.0d0 * ky))))))) * sin(th)
                else if (t_1 <= 1d-178) then
                    tmp = (sin(ky) / (sqrt(((1.0d0 - cos((2.0d0 * kx))) * 2.0d0)) / 2.0d0)) * sin(th)
                else if (t_1 <= 0.21d0) then
                    tmp = sin(th) / (sin(kx) / sin(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 <= -1.0) {
            		tmp = (Math.sin(ky) / Math.sqrt(((kx * kx) + (0.5 - (0.5 * Math.cos((2.0 * ky))))))) * Math.sin(th);
            	} else if (t_1 <= 1e-178) {
            		tmp = (Math.sin(ky) / (Math.sqrt(((1.0 - Math.cos((2.0 * kx))) * 2.0)) / 2.0)) * Math.sin(th);
            	} else if (t_1 <= 0.21) {
            		tmp = Math.sin(th) / (Math.sin(kx) / Math.sin(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 <= -1.0:
            		tmp = (math.sin(ky) / math.sqrt(((kx * kx) + (0.5 - (0.5 * math.cos((2.0 * ky))))))) * math.sin(th)
            	elif t_1 <= 1e-178:
            		tmp = (math.sin(ky) / (math.sqrt(((1.0 - math.cos((2.0 * kx))) * 2.0)) / 2.0)) * math.sin(th)
            	elif t_1 <= 0.21:
            		tmp = math.sin(th) / (math.sin(kx) / math.sin(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 <= -1.0)
            		tmp = Float64(Float64(sin(ky) / sqrt(Float64(Float64(kx * kx) + Float64(0.5 - Float64(0.5 * cos(Float64(2.0 * ky))))))) * sin(th));
            	elseif (t_1 <= 1e-178)
            		tmp = Float64(Float64(sin(ky) / Float64(sqrt(Float64(Float64(1.0 - cos(Float64(2.0 * kx))) * 2.0)) / 2.0)) * sin(th));
            	elseif (t_1 <= 0.21)
            		tmp = Float64(sin(th) / Float64(sin(kx) / sin(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 <= -1.0)
            		tmp = (sin(ky) / sqrt(((kx * kx) + (0.5 - (0.5 * cos((2.0 * ky))))))) * sin(th);
            	elseif (t_1 <= 1e-178)
            		tmp = (sin(ky) / (sqrt(((1.0 - cos((2.0 * kx))) * 2.0)) / 2.0)) * sin(th);
            	elseif (t_1 <= 0.21)
            		tmp = sin(th) / (sin(kx) / sin(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, -1.0], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(kx * kx), $MachinePrecision] + N[(0.5 - N[(0.5 * N[Cos[N[(2.0 * ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 1e-178], N[(N[(N[Sin[ky], $MachinePrecision] / N[(N[Sqrt[N[(N[(1.0 - N[Cos[N[(2.0 * kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 0.21], N[(N[Sin[th], $MachinePrecision] / N[(N[Sin[kx], $MachinePrecision] / N[Sin[ky], $MachinePrecision]), $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 -1:\\
            \;\;\;\;\frac{\sin ky}{\sqrt{kx \cdot kx + \left(0.5 - 0.5 \cdot \cos \left(2 \cdot ky\right)\right)}} \cdot \sin th\\
            
            \mathbf{elif}\;t\_1 \leq 10^{-178}:\\
            \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\left(1 - \cos \left(2 \cdot kx\right)\right) \cdot 2}}{2}} \cdot \sin th\\
            
            \mathbf{elif}\;t\_1 \leq 0.21:\\
            \;\;\;\;\frac{\sin th}{\frac{\sin kx}{\sin ky}}\\
            
            \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 79.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 \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
              4. Step-by-step derivation
                1. unpow2N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + \color{blue}{\left(0.5 - 0.5 \cdot \cos \left(2 \cdot ky\right)\right)}}} \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))))) < 9.9999999999999995e-179

              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-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-sin.f64N/A

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

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

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

                  \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
                10. unpow2N/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 \]
                11. 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 \]
                12. 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 \]
                13. 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 \]
                14. 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 \]
                15. 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 \]
                16. 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 \]
                17. 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 \]
              4. Applied rewrites83.8%

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

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

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

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

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

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

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

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

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

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

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

                if 9.9999999999999995e-179 < (/.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.209999999999999992

                1. Initial program 99.7%

                  \[\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. *-commutativeN/A

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

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

                    \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                  5. un-div-invN/A

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

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

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

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

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

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

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

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

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

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

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

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

                  \[\leadsto \frac{\sin th}{\frac{\color{blue}{\sin kx}}{\sin ky}} \]
                6. Step-by-step derivation
                  1. lower-sin.f6448.2

                    \[\leadsto \frac{\sin th}{\frac{\color{blue}{\sin kx}}{\sin ky}} \]
                7. Applied rewrites48.2%

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

                if 0.209999999999999992 < (/.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 89.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.f6463.6

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

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

                \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -1:\\ \;\;\;\;\frac{\sin ky}{\sqrt{kx \cdot kx + \left(0.5 - 0.5 \cdot \cos \left(2 \cdot ky\right)\right)}} \cdot \sin th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 10^{-178}:\\ \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\left(1 - \cos \left(2 \cdot kx\right)\right) \cdot 2}}{2}} \cdot \sin th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.21:\\ \;\;\;\;\frac{\sin th}{\frac{\sin kx}{\sin ky}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
              11. Add Preprocessing

              Alternative 12: 56.0% 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 -0.78:\\ \;\;\;\;\frac{\sin ky}{\sqrt{kx \cdot kx + \left(0.5 - 0.5 \cdot \cos \left(2 \cdot ky\right)\right)}} \cdot \sin th\\ \mathbf{elif}\;t\_1 \leq 0.21:\\ \;\;\;\;\frac{\sin th}{\frac{\sin kx}{\sin ky}}\\ \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 -0.78)
                   (*
                    (/ (sin ky) (sqrt (+ (* kx kx) (- 0.5 (* 0.5 (cos (* 2.0 ky)))))))
                    (sin th))
                   (if (<= t_1 0.21) (/ (sin th) (/ (sin kx) (sin 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 <= -0.78) {
              		tmp = (sin(ky) / sqrt(((kx * kx) + (0.5 - (0.5 * cos((2.0 * ky))))))) * sin(th);
              	} else if (t_1 <= 0.21) {
              		tmp = sin(th) / (sin(kx) / sin(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 <= (-0.78d0)) then
                      tmp = (sin(ky) / sqrt(((kx * kx) + (0.5d0 - (0.5d0 * cos((2.0d0 * ky))))))) * sin(th)
                  else if (t_1 <= 0.21d0) then
                      tmp = sin(th) / (sin(kx) / sin(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 <= -0.78) {
              		tmp = (Math.sin(ky) / Math.sqrt(((kx * kx) + (0.5 - (0.5 * Math.cos((2.0 * ky))))))) * Math.sin(th);
              	} else if (t_1 <= 0.21) {
              		tmp = Math.sin(th) / (Math.sin(kx) / Math.sin(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 <= -0.78:
              		tmp = (math.sin(ky) / math.sqrt(((kx * kx) + (0.5 - (0.5 * math.cos((2.0 * ky))))))) * math.sin(th)
              	elif t_1 <= 0.21:
              		tmp = math.sin(th) / (math.sin(kx) / math.sin(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 <= -0.78)
              		tmp = Float64(Float64(sin(ky) / sqrt(Float64(Float64(kx * kx) + Float64(0.5 - Float64(0.5 * cos(Float64(2.0 * ky))))))) * sin(th));
              	elseif (t_1 <= 0.21)
              		tmp = Float64(sin(th) / Float64(sin(kx) / sin(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 <= -0.78)
              		tmp = (sin(ky) / sqrt(((kx * kx) + (0.5 - (0.5 * cos((2.0 * ky))))))) * sin(th);
              	elseif (t_1 <= 0.21)
              		tmp = sin(th) / (sin(kx) / sin(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, -0.78], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(kx * kx), $MachinePrecision] + N[(0.5 - N[(0.5 * N[Cos[N[(2.0 * ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 0.21], N[(N[Sin[th], $MachinePrecision] / N[(N[Sin[kx], $MachinePrecision] / N[Sin[ky], $MachinePrecision]), $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 -0.78:\\
              \;\;\;\;\frac{\sin ky}{\sqrt{kx \cdot kx + \left(0.5 - 0.5 \cdot \cos \left(2 \cdot ky\right)\right)}} \cdot \sin th\\
              
              \mathbf{elif}\;t\_1 \leq 0.21:\\
              \;\;\;\;\frac{\sin th}{\frac{\sin kx}{\sin ky}}\\
              
              \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.78000000000000003

                1. Initial program 82.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 \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
                4. Step-by-step derivation
                  1. unpow2N/A

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

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

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

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

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

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

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

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

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

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

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

                    \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + \left(\frac{1}{2} - \frac{1}{2} \cdot \color{blue}{\cos \left(ky \cdot 2\right)}\right)}} \cdot \sin th \]
                  10. lower-*.f6445.9

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

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

                    \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + \left(\frac{1}{2} - \frac{1}{2} \cdot \cos \color{blue}{\left(2 \cdot ky\right)}\right)}} \cdot \sin th \]
                  13. lower-*.f6445.9

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

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

                if -0.78000000000000003 < (/.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.209999999999999992

                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-*.f64N/A

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

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

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

                    \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                  5. un-div-invN/A

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

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

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

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

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

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

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

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

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

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

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

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

                  \[\leadsto \frac{\sin th}{\frac{\color{blue}{\sin kx}}{\sin ky}} \]
                6. Step-by-step derivation
                  1. lower-sin.f6451.1

                    \[\leadsto \frac{\sin th}{\frac{\color{blue}{\sin kx}}{\sin ky}} \]
                7. Applied rewrites51.1%

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

                if 0.209999999999999992 < (/.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 89.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.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 simplification54.3%

                \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -0.78:\\ \;\;\;\;\frac{\sin ky}{\sqrt{kx \cdot kx + \left(0.5 - 0.5 \cdot \cos \left(2 \cdot ky\right)\right)}} \cdot \sin th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.21:\\ \;\;\;\;\frac{\sin th}{\frac{\sin kx}{\sin ky}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
              5. Add Preprocessing

              Alternative 13: 45.0% 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 10^{-178}:\\ \;\;\;\;\frac{\mathsf{fma}\left(-0.16666666666666666, ky \cdot ky, 1\right) \cdot ky}{\frac{\sqrt{1 - \cos \left(2 \cdot kx\right)} \cdot \sqrt{2}}{2}} \cdot \sin th\\ \mathbf{elif}\;t\_1 \leq 0.005:\\ \;\;\;\;\frac{\sin th}{\frac{\sin kx}{ky}}\\ \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 1e-178)
                   (*
                    (/
                     (* (fma -0.16666666666666666 (* ky ky) 1.0) ky)
                     (/ (* (sqrt (- 1.0 (cos (* 2.0 kx)))) (sqrt 2.0)) 2.0))
                    (sin th))
                   (if (<= t_1 0.005) (/ (sin th) (/ (sin kx) 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 <= 1e-178) {
              		tmp = ((fma(-0.16666666666666666, (ky * ky), 1.0) * ky) / ((sqrt((1.0 - cos((2.0 * kx)))) * sqrt(2.0)) / 2.0)) * sin(th);
              	} else if (t_1 <= 0.005) {
              		tmp = sin(th) / (sin(kx) / ky);
              	} else {
              		tmp = 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 <= 1e-178)
              		tmp = Float64(Float64(Float64(fma(-0.16666666666666666, Float64(ky * ky), 1.0) * ky) / Float64(Float64(sqrt(Float64(1.0 - cos(Float64(2.0 * kx)))) * sqrt(2.0)) / 2.0)) * sin(th));
              	elseif (t_1 <= 0.005)
              		tmp = Float64(sin(th) / Float64(sin(kx) / ky));
              	else
              		tmp = sin(th);
              	end
              	return 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, 1e-178], N[(N[(N[(N[(-0.16666666666666666 * N[(ky * ky), $MachinePrecision] + 1.0), $MachinePrecision] * ky), $MachinePrecision] / N[(N[(N[Sqrt[N[(1.0 - N[Cos[N[(2.0 * kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 0.005], N[(N[Sin[th], $MachinePrecision] / N[(N[Sin[kx], $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 10^{-178}:\\
              \;\;\;\;\frac{\mathsf{fma}\left(-0.16666666666666666, ky \cdot ky, 1\right) \cdot ky}{\frac{\sqrt{1 - \cos \left(2 \cdot kx\right)} \cdot \sqrt{2}}{2}} \cdot \sin th\\
              
              \mathbf{elif}\;t\_1 \leq 0.005:\\
              \;\;\;\;\frac{\sin th}{\frac{\sin kx}{ky}}\\
              
              \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))))) < 9.9999999999999995e-179

                1. Initial program 92.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-sin.f64N/A

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

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

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

                    \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
                  10. unpow2N/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 \]
                  11. 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 \]
                  12. 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 \]
                  13. 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 \]
                  14. 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 \]
                  15. 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 \]
                  16. 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 \]
                  17. 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 \]
                4. Applied rewrites71.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                if 9.9999999999999995e-179 < (/.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. 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. *-commutativeN/A

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

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

                    \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                  5. un-div-invN/A

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

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

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

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

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

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

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

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

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

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

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

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

                  \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sin kx}{ky}}} \]
                6. Step-by-step derivation
                  1. lower-/.f64N/A

                    \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sin kx}{ky}}} \]
                  2. lower-sin.f6454.4

                    \[\leadsto \frac{\sin th}{\frac{\color{blue}{\sin kx}}{ky}} \]
                7. Applied rewrites54.4%

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

                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 90.4%

                  \[\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.f6460.6

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

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

              Alternative 14: 48.5% accurate, 0.8× speedup?

              \[\begin{array}{l} \\ \begin{array}{l} t_1 := {\sin kx}^{2}\\ \mathbf{if}\;t\_1 \leq 2 \cdot 10^{-314}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;t\_1 \leq 5 \cdot 10^{-17}:\\ \;\;\;\;\frac{\sin th}{\frac{\sqrt{ky \cdot ky + kx \cdot kx}}{\sin ky}}\\ \mathbf{else}:\\ \;\;\;\;\left(2 \cdot \left(\left(\sin th \cdot ky\right) \cdot \sqrt{0.5}\right)\right) \cdot \sqrt{{\left(1 - \cos \left(2 \cdot kx\right)\right)}^{-1}}\\ \end{array} \end{array} \]
              (FPCore (kx ky th)
               :precision binary64
               (let* ((t_1 (pow (sin kx) 2.0)))
                 (if (<= t_1 2e-314)
                   (sin th)
                   (if (<= t_1 5e-17)
                     (/ (sin th) (/ (sqrt (+ (* ky ky) (* kx kx))) (sin ky)))
                     (*
                      (* 2.0 (* (* (sin th) ky) (sqrt 0.5)))
                      (sqrt (pow (- 1.0 (cos (* 2.0 kx))) -1.0)))))))
              double code(double kx, double ky, double th) {
              	double t_1 = pow(sin(kx), 2.0);
              	double tmp;
              	if (t_1 <= 2e-314) {
              		tmp = sin(th);
              	} else if (t_1 <= 5e-17) {
              		tmp = sin(th) / (sqrt(((ky * ky) + (kx * kx))) / sin(ky));
              	} else {
              		tmp = (2.0 * ((sin(th) * ky) * sqrt(0.5))) * sqrt(pow((1.0 - cos((2.0 * kx))), -1.0));
              	}
              	return tmp;
              }
              
              real(8) function code(kx, ky, th)
                  real(8), intent (in) :: kx
                  real(8), intent (in) :: ky
                  real(8), intent (in) :: th
                  real(8) :: t_1
                  real(8) :: tmp
                  t_1 = sin(kx) ** 2.0d0
                  if (t_1 <= 2d-314) then
                      tmp = sin(th)
                  else if (t_1 <= 5d-17) then
                      tmp = sin(th) / (sqrt(((ky * ky) + (kx * kx))) / sin(ky))
                  else
                      tmp = (2.0d0 * ((sin(th) * ky) * sqrt(0.5d0))) * sqrt(((1.0d0 - cos((2.0d0 * kx))) ** (-1.0d0)))
                  end if
                  code = tmp
              end function
              
              public static double code(double kx, double ky, double th) {
              	double t_1 = Math.pow(Math.sin(kx), 2.0);
              	double tmp;
              	if (t_1 <= 2e-314) {
              		tmp = Math.sin(th);
              	} else if (t_1 <= 5e-17) {
              		tmp = Math.sin(th) / (Math.sqrt(((ky * ky) + (kx * kx))) / Math.sin(ky));
              	} else {
              		tmp = (2.0 * ((Math.sin(th) * ky) * Math.sqrt(0.5))) * Math.sqrt(Math.pow((1.0 - Math.cos((2.0 * kx))), -1.0));
              	}
              	return tmp;
              }
              
              def code(kx, ky, th):
              	t_1 = math.pow(math.sin(kx), 2.0)
              	tmp = 0
              	if t_1 <= 2e-314:
              		tmp = math.sin(th)
              	elif t_1 <= 5e-17:
              		tmp = math.sin(th) / (math.sqrt(((ky * ky) + (kx * kx))) / math.sin(ky))
              	else:
              		tmp = (2.0 * ((math.sin(th) * ky) * math.sqrt(0.5))) * math.sqrt(math.pow((1.0 - math.cos((2.0 * kx))), -1.0))
              	return tmp
              
              function code(kx, ky, th)
              	t_1 = sin(kx) ^ 2.0
              	tmp = 0.0
              	if (t_1 <= 2e-314)
              		tmp = sin(th);
              	elseif (t_1 <= 5e-17)
              		tmp = Float64(sin(th) / Float64(sqrt(Float64(Float64(ky * ky) + Float64(kx * kx))) / sin(ky)));
              	else
              		tmp = Float64(Float64(2.0 * Float64(Float64(sin(th) * ky) * sqrt(0.5))) * sqrt((Float64(1.0 - cos(Float64(2.0 * kx))) ^ -1.0)));
              	end
              	return tmp
              end
              
              function tmp_2 = code(kx, ky, th)
              	t_1 = sin(kx) ^ 2.0;
              	tmp = 0.0;
              	if (t_1 <= 2e-314)
              		tmp = sin(th);
              	elseif (t_1 <= 5e-17)
              		tmp = sin(th) / (sqrt(((ky * ky) + (kx * kx))) / sin(ky));
              	else
              		tmp = (2.0 * ((sin(th) * ky) * sqrt(0.5))) * sqrt(((1.0 - cos((2.0 * kx))) ^ -1.0));
              	end
              	tmp_2 = tmp;
              end
              
              code[kx_, ky_, th_] := Block[{t$95$1 = N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]}, If[LessEqual[t$95$1, 2e-314], N[Sin[th], $MachinePrecision], If[LessEqual[t$95$1, 5e-17], N[(N[Sin[th], $MachinePrecision] / N[(N[Sqrt[N[(N[(ky * ky), $MachinePrecision] + N[(kx * kx), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sin[ky], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * N[(N[(N[Sin[th], $MachinePrecision] * ky), $MachinePrecision] * N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[Power[N[(1.0 - N[Cos[N[(2.0 * kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
              
              \begin{array}{l}
              
              \\
              \begin{array}{l}
              t_1 := {\sin kx}^{2}\\
              \mathbf{if}\;t\_1 \leq 2 \cdot 10^{-314}:\\
              \;\;\;\;\sin th\\
              
              \mathbf{elif}\;t\_1 \leq 5 \cdot 10^{-17}:\\
              \;\;\;\;\frac{\sin th}{\frac{\sqrt{ky \cdot ky + kx \cdot kx}}{\sin ky}}\\
              
              \mathbf{else}:\\
              \;\;\;\;\left(2 \cdot \left(\left(\sin th \cdot ky\right) \cdot \sqrt{0.5}\right)\right) \cdot \sqrt{{\left(1 - \cos \left(2 \cdot kx\right)\right)}^{-1}}\\
              
              
              \end{array}
              \end{array}
              
              Derivation
              1. Split input into 3 regimes
              2. if (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) < 1.9999999999e-314

                1. Initial program 71.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}{\sin th} \]
                4. Step-by-step derivation
                  1. lower-sin.f6450.7

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

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

                if 1.9999999999e-314 < (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) < 4.9999999999999999e-17

                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 0

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

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

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

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

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

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

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

                  \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + \color{blue}{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. *-commutativeN/A

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

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

                    \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{kx \cdot kx + ky \cdot ky}}{\sin ky}}} \]
                  5. un-div-invN/A

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

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

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

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

                if 4.9999999999999999e-17 < (pow.f64 (sin.f64 kx) #s(literal 2 binary64))

                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-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-sin.f64N/A

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

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

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

                    \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
                  10. unpow2N/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 \]
                  11. 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 \]
                  12. 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 \]
                  13. 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 \]
                  14. 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 \]
                  15. 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 \]
                  16. 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 \]
                  17. 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 \]
                4. Applied rewrites99.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                    \[\leadsto \left(2 \cdot \left(\left(\sin th \cdot ky\right) \cdot \sqrt{0.5}\right)\right) \cdot \sqrt{\frac{1}{1 - \cos \color{blue}{\left(2 \cdot kx\right)}}} \]
                7. Applied rewrites51.3%

                  \[\leadsto \color{blue}{\left(2 \cdot \left(\left(\sin th \cdot ky\right) \cdot \sqrt{0.5}\right)\right) \cdot \sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}}} \]
              3. Recombined 3 regimes into one program.
              4. Final simplification55.0%

                \[\leadsto \begin{array}{l} \mathbf{if}\;{\sin kx}^{2} \leq 2 \cdot 10^{-314}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;{\sin kx}^{2} \leq 5 \cdot 10^{-17}:\\ \;\;\;\;\frac{\sin th}{\frac{\sqrt{ky \cdot ky + kx \cdot kx}}{\sin ky}}\\ \mathbf{else}:\\ \;\;\;\;\left(2 \cdot \left(\left(\sin th \cdot ky\right) \cdot \sqrt{0.5}\right)\right) \cdot \sqrt{{\left(1 - \cos \left(2 \cdot kx\right)\right)}^{-1}}\\ \end{array} \]
              5. Add Preprocessing

              Alternative 15: 43.5% accurate, 0.8× speedup?

              \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.005:\\ \;\;\;\;\frac{\sin th}{\frac{\sin kx}{ky}}\\ \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.005)
                 (/ (sin th) (/ (sin kx) ky))
                 (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.005) {
              		tmp = sin(th) / (sin(kx) / ky);
              	} else {
              		tmp = sin(th);
              	}
              	return tmp;
              }
              
              real(8) function code(kx, ky, th)
                  real(8), intent (in) :: kx
                  real(8), intent (in) :: ky
                  real(8), intent (in) :: th
                  real(8) :: tmp
                  if ((sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) <= 0.005d0) then
                      tmp = sin(th) / (sin(kx) / ky)
                  else
                      tmp = sin(th)
                  end if
                  code = tmp
              end function
              
              public static double code(double kx, double ky, double th) {
              	double tmp;
              	if ((Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) <= 0.005) {
              		tmp = Math.sin(th) / (Math.sin(kx) / ky);
              	} 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.005:
              		tmp = math.sin(th) / (math.sin(kx) / ky)
              	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.005)
              		tmp = Float64(sin(th) / Float64(sin(kx) / ky));
              	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.005)
              		tmp = sin(th) / (sin(kx) / ky);
              	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.005], N[(N[Sin[th], $MachinePrecision] / N[(N[Sin[kx], $MachinePrecision] / ky), $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.005:\\
              \;\;\;\;\frac{\sin th}{\frac{\sin kx}{ky}}\\
              
              \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))))) < 0.0050000000000000001

                1. Initial program 94.0%

                  \[\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. *-commutativeN/A

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

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

                    \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                  5. un-div-invN/A

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

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

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

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

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

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

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

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

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

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

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

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

                  \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sin kx}{ky}}} \]
                6. Step-by-step derivation
                  1. lower-/.f64N/A

                    \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sin kx}{ky}}} \]
                  2. lower-sin.f6437.1

                    \[\leadsto \frac{\sin th}{\frac{\color{blue}{\sin kx}}{ky}} \]
                7. Applied rewrites37.1%

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

                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 90.4%

                  \[\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.f6460.6

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

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

              Alternative 16: 43.5% accurate, 0.8× speedup?

              \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.005:\\ \;\;\;\;\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.005)
                 (* (/ 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.005) {
              		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.005d0) 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.005) {
              		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.005:
              		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.005)
              		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.005)
              		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.005], 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.005:\\
              \;\;\;\;\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))))) < 0.0050000000000000001

                1. Initial program 94.0%

                  \[\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.f6437.0

                    \[\leadsto \frac{ky}{\color{blue}{\sin kx}} \cdot \sin th \]
                5. Applied rewrites37.0%

                  \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \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 90.4%

                  \[\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.f6460.6

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

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

              Alternative 17: 30.6% accurate, 0.9× speedup?

              \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 5 \cdot 10^{-30}:\\ \;\;\;\;\frac{\sin th}{\mathsf{fma}\left(\frac{\frac{\mathsf{fma}\left(ky \cdot ky, 0.16666666666666666, 0.5\right)}{ky}}{ky}, kx \cdot kx, 1\right)}\\ \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-30)
                 (/
                  (sin th)
                  (fma (/ (/ (fma (* ky ky) 0.16666666666666666 0.5) ky) ky) (* kx kx) 1.0))
                 (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-30) {
              		tmp = sin(th) / fma(((fma((ky * ky), 0.16666666666666666, 0.5) / ky) / ky), (kx * kx), 1.0);
              	} 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)))) <= 5e-30)
              		tmp = Float64(sin(th) / fma(Float64(Float64(fma(Float64(ky * ky), 0.16666666666666666, 0.5) / ky) / ky), Float64(kx * kx), 1.0));
              	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], 5e-30], N[(N[Sin[th], $MachinePrecision] / N[(N[(N[(N[(N[(ky * ky), $MachinePrecision] * 0.16666666666666666 + 0.5), $MachinePrecision] / ky), $MachinePrecision] / ky), $MachinePrecision] * N[(kx * kx), $MachinePrecision] + 1.0), $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^{-30}:\\
              \;\;\;\;\frac{\sin th}{\mathsf{fma}\left(\frac{\frac{\mathsf{fma}\left(ky \cdot ky, 0.16666666666666666, 0.5\right)}{ky}}{ky}, kx \cdot kx, 1\right)}\\
              
              \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))))) < 4.99999999999999972e-30

                1. Initial program 93.7%

                  \[\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. *-commutativeN/A

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

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

                    \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                  5. un-div-invN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                    \[\leadsto \frac{\sin th}{\color{blue}{\frac{\frac{1}{2}}{{\sin ky}^{2}} \cdot {kx}^{2}} + 1} \]
                  4. metadata-evalN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

                  if 4.99999999999999972e-30 < (/.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 91.1%

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

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

                    \[\leadsto \color{blue}{\sin th} \]
                10. Recombined 2 regimes into one program.
                11. Add Preprocessing

                Alternative 18: 30.4% accurate, 0.9× speedup?

                \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 5 \cdot 10^{-30}:\\ \;\;\;\;\frac{\sin th}{\mathsf{fma}\left(\frac{0.5}{ky \cdot ky}, kx \cdot kx, 1\right)}\\ \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-30)
                   (/ (sin th) (fma (/ 0.5 (* ky ky)) (* kx kx) 1.0))
                   (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-30) {
                		tmp = sin(th) / fma((0.5 / (ky * ky)), (kx * kx), 1.0);
                	} 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)))) <= 5e-30)
                		tmp = Float64(sin(th) / fma(Float64(0.5 / Float64(ky * ky)), Float64(kx * kx), 1.0));
                	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], 5e-30], N[(N[Sin[th], $MachinePrecision] / N[(N[(0.5 / N[(ky * ky), $MachinePrecision]), $MachinePrecision] * N[(kx * kx), $MachinePrecision] + 1.0), $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^{-30}:\\
                \;\;\;\;\frac{\sin th}{\mathsf{fma}\left(\frac{0.5}{ky \cdot ky}, kx \cdot kx, 1\right)}\\
                
                \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))))) < 4.99999999999999972e-30

                  1. Initial program 93.7%

                    \[\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. *-commutativeN/A

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

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

                      \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                    5. un-div-invN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                      \[\leadsto \frac{\sin th}{\color{blue}{\frac{\frac{1}{2}}{{\sin ky}^{2}} \cdot {kx}^{2}} + 1} \]
                    4. metadata-evalN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

                    if 4.99999999999999972e-30 < (/.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 91.1%

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

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

                      \[\leadsto \color{blue}{\sin th} \]
                  10. Recombined 2 regimes into one program.
                  11. Add Preprocessing

                  Alternative 19: 14.9% 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 2 \cdot 10^{-307}:\\ \;\;\;\;\left(\left(-0.16666666666666666 \cdot th\right) \cdot th\right) \cdot th\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(th \cdot th, 0.008333333333333333, -0.16666666666666666\right), 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))
                        2e-307)
                     (* (* (* -0.16666666666666666 th) th) th)
                     (*
                      (fma
                       (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)) <= 2e-307) {
                  		tmp = ((-0.16666666666666666 * th) * th) * th;
                  	} else {
                  		tmp = fma(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)) <= 2e-307)
                  		tmp = Float64(Float64(Float64(-0.16666666666666666 * th) * th) * th);
                  	else
                  		tmp = Float64(fma(fma(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], 2e-307], N[(N[(N[(-0.16666666666666666 * th), $MachinePrecision] * th), $MachinePrecision] * th), $MachinePrecision], N[(N[(N[(N[(th * th), $MachinePrecision] * 0.008333333333333333 + -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 2 \cdot 10^{-307}:\\
                  \;\;\;\;\left(\left(-0.16666666666666666 \cdot th\right) \cdot th\right) \cdot th\\
                  
                  \mathbf{else}:\\
                  \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(th \cdot th, 0.008333333333333333, -0.16666666666666666\right), 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)) < 1.99999999999999982e-307

                    1. Initial program 93.1%

                      \[\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.f6423.3

                        \[\leadsto \color{blue}{\sin th} \]
                    5. Applied rewrites23.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 rewrites13.0%

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

                          \[\leadsto \left(\left(th \cdot th\right) \cdot -0.16666666666666666\right) \cdot th \]
                        2. Step-by-step derivation
                          1. Applied rewrites14.4%

                            \[\leadsto \left(\left(-0.16666666666666666 \cdot th\right) \cdot th\right) \cdot th \]

                          if 1.99999999999999982e-307 < (*.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 92.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}{\sin th} \]
                          4. Step-by-step derivation
                            1. lower-sin.f6427.1

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

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

                              \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(th \cdot th, 0.008333333333333333, -0.16666666666666666\right), th \cdot th, 1\right) \cdot \color{blue}{th} \]
                          8. Recombined 2 regimes into one program.
                          9. Add Preprocessing

                          Alternative 20: 14.9% 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 2 \cdot 10^{-307}:\\ \;\;\;\;\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))
                                2e-307)
                             (* (* (* -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)) <= 2e-307) {
                          		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)) <= 2e-307)
                          		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], 2e-307], 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 2 \cdot 10^{-307}:\\
                          \;\;\;\;\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)) < 1.99999999999999982e-307

                            1. Initial program 93.1%

                              \[\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.f6423.3

                                \[\leadsto \color{blue}{\sin th} \]
                            5. Applied rewrites23.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 rewrites13.0%

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

                                  \[\leadsto \left(\left(th \cdot th\right) \cdot -0.16666666666666666\right) \cdot th \]
                                2. Step-by-step derivation
                                  1. Applied rewrites14.4%

                                    \[\leadsto \left(\left(-0.16666666666666666 \cdot th\right) \cdot th\right) \cdot th \]

                                  if 1.99999999999999982e-307 < (*.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 92.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}{\sin th} \]
                                  4. Step-by-step derivation
                                    1. lower-sin.f6427.1

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

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

                                      \[\leadsto \mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot \color{blue}{th} \]
                                    2. Step-by-step derivation
                                      1. Applied rewrites11.6%

                                        \[\leadsto \mathsf{fma}\left(-0.16666666666666666 \cdot th, th, 1\right) \cdot th \]
                                    3. Recombined 2 regimes into one program.
                                    4. Add Preprocessing

                                    Alternative 21: 30.0% accurate, 1.0× speedup?

                                    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 2.7 \cdot 10^{-30}:\\ \;\;\;\;\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)))) 2.7e-30)
                                       (* (* (* -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)))) <= 2.7e-30) {
                                    		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)))) <= 2.7d-30) 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)))) <= 2.7e-30) {
                                    		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)))) <= 2.7e-30:
                                    		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)))) <= 2.7e-30)
                                    		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)))) <= 2.7e-30)
                                    		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], 2.7e-30], 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 2.7 \cdot 10^{-30}:\\
                                    \;\;\;\;\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))))) < 2.69999999999999987e-30

                                      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.f643.8

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

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

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

                                            \[\leadsto \left(\left(th \cdot th\right) \cdot -0.16666666666666666\right) \cdot th \]
                                          2. Step-by-step derivation
                                            1. Applied rewrites14.1%

                                              \[\leadsto \left(\left(-0.16666666666666666 \cdot th\right) \cdot th\right) \cdot th \]

                                            if 2.69999999999999987e-30 < (/.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 91.2%

                                              \[\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.f6456.2

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

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

                                          Alternative 22: 48.5% accurate, 1.1× speedup?

                                          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.025:\\ \;\;\;\;\left(2 \cdot \left(\left(\sin th \cdot ky\right) \cdot \sqrt{0.5}\right)\right) \cdot \sqrt{{\left(1 - \cos \left(2 \cdot kx\right)\right)}^{-1}}\\ \mathbf{elif}\;\sin kx \leq 4 \cdot 10^{-72}:\\ \;\;\;\;\frac{\sin th}{\mathsf{fma}\left(\frac{0.5 \cdot kx}{\sin ky}, \frac{kx}{\sin ky}, 1\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th}{\frac{\sin kx}{\sin ky}}\\ \end{array} \end{array} \]
                                          (FPCore (kx ky th)
                                           :precision binary64
                                           (if (<= (sin kx) -0.025)
                                             (*
                                              (* 2.0 (* (* (sin th) ky) (sqrt 0.5)))
                                              (sqrt (pow (- 1.0 (cos (* 2.0 kx))) -1.0)))
                                             (if (<= (sin kx) 4e-72)
                                               (/ (sin th) (fma (/ (* 0.5 kx) (sin ky)) (/ kx (sin ky)) 1.0))
                                               (/ (sin th) (/ (sin kx) (sin ky))))))
                                          double code(double kx, double ky, double th) {
                                          	double tmp;
                                          	if (sin(kx) <= -0.025) {
                                          		tmp = (2.0 * ((sin(th) * ky) * sqrt(0.5))) * sqrt(pow((1.0 - cos((2.0 * kx))), -1.0));
                                          	} else if (sin(kx) <= 4e-72) {
                                          		tmp = sin(th) / fma(((0.5 * kx) / sin(ky)), (kx / sin(ky)), 1.0);
                                          	} else {
                                          		tmp = sin(th) / (sin(kx) / sin(ky));
                                          	}
                                          	return tmp;
                                          }
                                          
                                          function code(kx, ky, th)
                                          	tmp = 0.0
                                          	if (sin(kx) <= -0.025)
                                          		tmp = Float64(Float64(2.0 * Float64(Float64(sin(th) * ky) * sqrt(0.5))) * sqrt((Float64(1.0 - cos(Float64(2.0 * kx))) ^ -1.0)));
                                          	elseif (sin(kx) <= 4e-72)
                                          		tmp = Float64(sin(th) / fma(Float64(Float64(0.5 * kx) / sin(ky)), Float64(kx / sin(ky)), 1.0));
                                          	else
                                          		tmp = Float64(sin(th) / Float64(sin(kx) / sin(ky)));
                                          	end
                                          	return tmp
                                          end
                                          
                                          code[kx_, ky_, th_] := If[LessEqual[N[Sin[kx], $MachinePrecision], -0.025], N[(N[(2.0 * N[(N[(N[Sin[th], $MachinePrecision] * ky), $MachinePrecision] * N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[Power[N[(1.0 - N[Cos[N[(2.0 * kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[kx], $MachinePrecision], 4e-72], N[(N[Sin[th], $MachinePrecision] / N[(N[(N[(0.5 * kx), $MachinePrecision] / N[Sin[ky], $MachinePrecision]), $MachinePrecision] * N[(kx / N[Sin[ky], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[Sin[th], $MachinePrecision] / N[(N[Sin[kx], $MachinePrecision] / N[Sin[ky], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
                                          
                                          \begin{array}{l}
                                          
                                          \\
                                          \begin{array}{l}
                                          \mathbf{if}\;\sin kx \leq -0.025:\\
                                          \;\;\;\;\left(2 \cdot \left(\left(\sin th \cdot ky\right) \cdot \sqrt{0.5}\right)\right) \cdot \sqrt{{\left(1 - \cos \left(2 \cdot kx\right)\right)}^{-1}}\\
                                          
                                          \mathbf{elif}\;\sin kx \leq 4 \cdot 10^{-72}:\\
                                          \;\;\;\;\frac{\sin th}{\mathsf{fma}\left(\frac{0.5 \cdot kx}{\sin ky}, \frac{kx}{\sin ky}, 1\right)}\\
                                          
                                          \mathbf{else}:\\
                                          \;\;\;\;\frac{\sin th}{\frac{\sin kx}{\sin ky}}\\
                                          
                                          
                                          \end{array}
                                          \end{array}
                                          
                                          Derivation
                                          1. Split input into 3 regimes
                                          2. if (sin.f64 kx) < -0.025000000000000001

                                            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-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-sin.f64N/A

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

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

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

                                                \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
                                              10. unpow2N/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 \]
                                              11. 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 \]
                                              12. 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 \]
                                              13. 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 \]
                                              14. 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 \]
                                              15. 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 \]
                                              16. 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 \]
                                              17. 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 \]
                                            4. Applied rewrites99.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                \[\leadsto \left(2 \cdot \left(\left(\sin th \cdot ky\right) \cdot \sqrt{0.5}\right)\right) \cdot \sqrt{\frac{1}{1 - \cos \color{blue}{\left(2 \cdot kx\right)}}} \]
                                            7. Applied rewrites45.0%

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

                                            if -0.025000000000000001 < (sin.f64 kx) < 3.9999999999999999e-72

                                            1. Initial program 84.0%

                                              \[\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. *-commutativeN/A

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

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

                                                \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                              5. un-div-invN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                \[\leadsto \frac{\sin th}{\color{blue}{\frac{\frac{1}{2}}{{\sin ky}^{2}} \cdot {kx}^{2}} + 1} \]
                                              4. metadata-evalN/A

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

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

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

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

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

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

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

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

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

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

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

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

                                              if 3.9999999999999999e-72 < (sin.f64 kx)

                                              1. Initial program 99.7%

                                                \[\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. *-commutativeN/A

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

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

                                                  \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                5. un-div-invN/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                6. lower-/.f64N/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                7. lower-/.f6499.7

                                                  \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                8. lift-sqrt.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}}{\sin ky}} \]
                                                9. lift-+.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}}{\sin ky}} \]
                                                10. +-commutativeN/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}}{\sin ky}} \]
                                                11. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin ky}^{2}} + {\sin kx}^{2}}}{\sin ky}} \]
                                                12. unpow2N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}}{\sin ky}} \]
                                                13. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\sin ky \cdot \sin ky + \color{blue}{{\sin kx}^{2}}}}{\sin ky}} \]
                                                14. unpow2N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}}{\sin ky}} \]
                                                15. lower-hypot.f6499.7

                                                  \[\leadsto \frac{\sin th}{\frac{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{\sin ky}} \]
                                              4. Applied rewrites99.7%

                                                \[\leadsto \color{blue}{\frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin ky}}} \]
                                              5. Taylor expanded in ky around 0

                                                \[\leadsto \frac{\sin th}{\frac{\color{blue}{\sin kx}}{\sin ky}} \]
                                              6. Step-by-step derivation
                                                1. lower-sin.f6466.3

                                                  \[\leadsto \frac{\sin th}{\frac{\color{blue}{\sin kx}}{\sin ky}} \]
                                              7. Applied rewrites66.3%

                                                \[\leadsto \frac{\sin th}{\frac{\color{blue}{\sin kx}}{\sin ky}} \]
                                            9. Recombined 3 regimes into one program.
                                            10. Final simplification51.4%

                                              \[\leadsto \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.025:\\ \;\;\;\;\left(2 \cdot \left(\left(\sin th \cdot ky\right) \cdot \sqrt{0.5}\right)\right) \cdot \sqrt{{\left(1 - \cos \left(2 \cdot kx\right)\right)}^{-1}}\\ \mathbf{elif}\;\sin kx \leq 4 \cdot 10^{-72}:\\ \;\;\;\;\frac{\sin th}{\mathsf{fma}\left(\frac{0.5 \cdot kx}{\sin ky}, \frac{kx}{\sin ky}, 1\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th}{\frac{\sin kx}{\sin ky}}\\ \end{array} \]
                                            11. Add Preprocessing

                                            Alternative 23: 47.2% accurate, 1.2× speedup?

                                            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.02:\\ \;\;\;\;\left(2 \cdot \left(\left(\sin th \cdot ky\right) \cdot \sqrt{0.5}\right)\right) \cdot \sqrt{{\left(1 - \cos \left(2 \cdot kx\right)\right)}^{-1}}\\ \mathbf{elif}\;\sin kx \leq 4 \cdot 10^{-72}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th}{\frac{\sin kx}{\sin ky}}\\ \end{array} \end{array} \]
                                            (FPCore (kx ky th)
                                             :precision binary64
                                             (if (<= (sin kx) -0.02)
                                               (*
                                                (* 2.0 (* (* (sin th) ky) (sqrt 0.5)))
                                                (sqrt (pow (- 1.0 (cos (* 2.0 kx))) -1.0)))
                                               (if (<= (sin kx) 4e-72) (sin th) (/ (sin th) (/ (sin kx) (sin ky))))))
                                            double code(double kx, double ky, double th) {
                                            	double tmp;
                                            	if (sin(kx) <= -0.02) {
                                            		tmp = (2.0 * ((sin(th) * ky) * sqrt(0.5))) * sqrt(pow((1.0 - cos((2.0 * kx))), -1.0));
                                            	} else if (sin(kx) <= 4e-72) {
                                            		tmp = sin(th);
                                            	} else {
                                            		tmp = sin(th) / (sin(kx) / sin(ky));
                                            	}
                                            	return tmp;
                                            }
                                            
                                            real(8) function code(kx, ky, th)
                                                real(8), intent (in) :: kx
                                                real(8), intent (in) :: ky
                                                real(8), intent (in) :: th
                                                real(8) :: tmp
                                                if (sin(kx) <= (-0.02d0)) then
                                                    tmp = (2.0d0 * ((sin(th) * ky) * sqrt(0.5d0))) * sqrt(((1.0d0 - cos((2.0d0 * kx))) ** (-1.0d0)))
                                                else if (sin(kx) <= 4d-72) then
                                                    tmp = sin(th)
                                                else
                                                    tmp = sin(th) / (sin(kx) / sin(ky))
                                                end if
                                                code = tmp
                                            end function
                                            
                                            public static double code(double kx, double ky, double th) {
                                            	double tmp;
                                            	if (Math.sin(kx) <= -0.02) {
                                            		tmp = (2.0 * ((Math.sin(th) * ky) * Math.sqrt(0.5))) * Math.sqrt(Math.pow((1.0 - Math.cos((2.0 * kx))), -1.0));
                                            	} else if (Math.sin(kx) <= 4e-72) {
                                            		tmp = Math.sin(th);
                                            	} else {
                                            		tmp = Math.sin(th) / (Math.sin(kx) / Math.sin(ky));
                                            	}
                                            	return tmp;
                                            }
                                            
                                            def code(kx, ky, th):
                                            	tmp = 0
                                            	if math.sin(kx) <= -0.02:
                                            		tmp = (2.0 * ((math.sin(th) * ky) * math.sqrt(0.5))) * math.sqrt(math.pow((1.0 - math.cos((2.0 * kx))), -1.0))
                                            	elif math.sin(kx) <= 4e-72:
                                            		tmp = math.sin(th)
                                            	else:
                                            		tmp = math.sin(th) / (math.sin(kx) / math.sin(ky))
                                            	return tmp
                                            
                                            function code(kx, ky, th)
                                            	tmp = 0.0
                                            	if (sin(kx) <= -0.02)
                                            		tmp = Float64(Float64(2.0 * Float64(Float64(sin(th) * ky) * sqrt(0.5))) * sqrt((Float64(1.0 - cos(Float64(2.0 * kx))) ^ -1.0)));
                                            	elseif (sin(kx) <= 4e-72)
                                            		tmp = sin(th);
                                            	else
                                            		tmp = Float64(sin(th) / Float64(sin(kx) / sin(ky)));
                                            	end
                                            	return tmp
                                            end
                                            
                                            function tmp_2 = code(kx, ky, th)
                                            	tmp = 0.0;
                                            	if (sin(kx) <= -0.02)
                                            		tmp = (2.0 * ((sin(th) * ky) * sqrt(0.5))) * sqrt(((1.0 - cos((2.0 * kx))) ^ -1.0));
                                            	elseif (sin(kx) <= 4e-72)
                                            		tmp = sin(th);
                                            	else
                                            		tmp = sin(th) / (sin(kx) / sin(ky));
                                            	end
                                            	tmp_2 = tmp;
                                            end
                                            
                                            code[kx_, ky_, th_] := If[LessEqual[N[Sin[kx], $MachinePrecision], -0.02], N[(N[(2.0 * N[(N[(N[Sin[th], $MachinePrecision] * ky), $MachinePrecision] * N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[Power[N[(1.0 - N[Cos[N[(2.0 * kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[kx], $MachinePrecision], 4e-72], N[Sin[th], $MachinePrecision], N[(N[Sin[th], $MachinePrecision] / N[(N[Sin[kx], $MachinePrecision] / N[Sin[ky], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
                                            
                                            \begin{array}{l}
                                            
                                            \\
                                            \begin{array}{l}
                                            \mathbf{if}\;\sin kx \leq -0.02:\\
                                            \;\;\;\;\left(2 \cdot \left(\left(\sin th \cdot ky\right) \cdot \sqrt{0.5}\right)\right) \cdot \sqrt{{\left(1 - \cos \left(2 \cdot kx\right)\right)}^{-1}}\\
                                            
                                            \mathbf{elif}\;\sin kx \leq 4 \cdot 10^{-72}:\\
                                            \;\;\;\;\sin th\\
                                            
                                            \mathbf{else}:\\
                                            \;\;\;\;\frac{\sin th}{\frac{\sin kx}{\sin ky}}\\
                                            
                                            
                                            \end{array}
                                            \end{array}
                                            
                                            Derivation
                                            1. Split input into 3 regimes
                                            2. if (sin.f64 kx) < -0.0200000000000000004

                                              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-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-sin.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky} \cdot \sin ky + {\sin kx}^{2}}} \cdot \sin th \]
                                                7. lift-sin.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \color{blue}{\sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
                                                8. sin-multN/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2}} + {\sin kx}^{2}}} \cdot \sin th \]
                                                9. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
                                                10. unpow2N/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 \]
                                                11. 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 \]
                                                12. 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 \]
                                                13. 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 \]
                                                14. 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 \]
                                                15. 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 \]
                                                16. 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 \]
                                                17. 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 \]
                                              4. Applied rewrites99.3%

                                                \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}}} \cdot \sin th \]
                                              5. Taylor expanded in ky around 0

                                                \[\leadsto \color{blue}{2 \cdot \left(\left(ky \cdot \left(\sin th \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}}\right)} \]
                                              6. Step-by-step derivation
                                                1. associate-*r*N/A

                                                  \[\leadsto \color{blue}{\left(2 \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{\frac{1}{2}}\right)\right)\right) \cdot \sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}}} \]
                                                2. lower-*.f64N/A

                                                  \[\leadsto \color{blue}{\left(2 \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{\frac{1}{2}}\right)\right)\right) \cdot \sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}}} \]
                                                3. lower-*.f64N/A

                                                  \[\leadsto \color{blue}{\left(2 \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{\frac{1}{2}}\right)\right)\right)} \cdot \sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}} \]
                                                4. associate-*r*N/A

                                                  \[\leadsto \left(2 \cdot \color{blue}{\left(\left(ky \cdot \sin th\right) \cdot \sqrt{\frac{1}{2}}\right)}\right) \cdot \sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}} \]
                                                5. lower-*.f64N/A

                                                  \[\leadsto \left(2 \cdot \color{blue}{\left(\left(ky \cdot \sin th\right) \cdot \sqrt{\frac{1}{2}}\right)}\right) \cdot \sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}} \]
                                                6. *-commutativeN/A

                                                  \[\leadsto \left(2 \cdot \left(\color{blue}{\left(\sin th \cdot ky\right)} \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}} \]
                                                7. lower-*.f64N/A

                                                  \[\leadsto \left(2 \cdot \left(\color{blue}{\left(\sin th \cdot ky\right)} \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}} \]
                                                8. lower-sin.f64N/A

                                                  \[\leadsto \left(2 \cdot \left(\left(\color{blue}{\sin th} \cdot ky\right) \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}} \]
                                                9. lower-sqrt.f64N/A

                                                  \[\leadsto \left(2 \cdot \left(\left(\sin th \cdot ky\right) \cdot \color{blue}{\sqrt{\frac{1}{2}}}\right)\right) \cdot \sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}} \]
                                                10. lower-sqrt.f64N/A

                                                  \[\leadsto \left(2 \cdot \left(\left(\sin th \cdot ky\right) \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \color{blue}{\sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}}} \]
                                                11. lower-/.f64N/A

                                                  \[\leadsto \left(2 \cdot \left(\left(\sin th \cdot ky\right) \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{\color{blue}{\frac{1}{1 - \cos \left(2 \cdot kx\right)}}} \]
                                                12. lower--.f64N/A

                                                  \[\leadsto \left(2 \cdot \left(\left(\sin th \cdot ky\right) \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{\frac{1}{\color{blue}{1 - \cos \left(2 \cdot kx\right)}}} \]
                                                13. lower-cos.f64N/A

                                                  \[\leadsto \left(2 \cdot \left(\left(\sin th \cdot ky\right) \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{\frac{1}{1 - \color{blue}{\cos \left(2 \cdot kx\right)}}} \]
                                                14. lower-*.f6445.0

                                                  \[\leadsto \left(2 \cdot \left(\left(\sin th \cdot ky\right) \cdot \sqrt{0.5}\right)\right) \cdot \sqrt{\frac{1}{1 - \cos \color{blue}{\left(2 \cdot kx\right)}}} \]
                                              7. Applied rewrites45.0%

                                                \[\leadsto \color{blue}{\left(2 \cdot \left(\left(\sin th \cdot ky\right) \cdot \sqrt{0.5}\right)\right) \cdot \sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}}} \]

                                              if -0.0200000000000000004 < (sin.f64 kx) < 3.9999999999999999e-72

                                              1. Initial program 84.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}{\sin th} \]
                                              4. Step-by-step derivation
                                                1. lower-sin.f6443.5

                                                  \[\leadsto \color{blue}{\sin th} \]
                                              5. Applied rewrites43.5%

                                                \[\leadsto \color{blue}{\sin th} \]

                                              if 3.9999999999999999e-72 < (sin.f64 kx)

                                              1. Initial program 99.7%

                                                \[\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. *-commutativeN/A

                                                  \[\leadsto \color{blue}{\sin th \cdot \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                                                3. lift-/.f64N/A

                                                  \[\leadsto \sin th \cdot \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                                                4. clear-numN/A

                                                  \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                5. un-div-invN/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                6. lower-/.f64N/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                7. lower-/.f6499.7

                                                  \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                8. lift-sqrt.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}}{\sin ky}} \]
                                                9. lift-+.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}}{\sin ky}} \]
                                                10. +-commutativeN/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}}{\sin ky}} \]
                                                11. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin ky}^{2}} + {\sin kx}^{2}}}{\sin ky}} \]
                                                12. unpow2N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}}{\sin ky}} \]
                                                13. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\sin ky \cdot \sin ky + \color{blue}{{\sin kx}^{2}}}}{\sin ky}} \]
                                                14. unpow2N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}}{\sin ky}} \]
                                                15. lower-hypot.f6499.7

                                                  \[\leadsto \frac{\sin th}{\frac{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{\sin ky}} \]
                                              4. Applied rewrites99.7%

                                                \[\leadsto \color{blue}{\frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin ky}}} \]
                                              5. Taylor expanded in ky around 0

                                                \[\leadsto \frac{\sin th}{\frac{\color{blue}{\sin kx}}{\sin ky}} \]
                                              6. Step-by-step derivation
                                                1. lower-sin.f6466.3

                                                  \[\leadsto \frac{\sin th}{\frac{\color{blue}{\sin kx}}{\sin ky}} \]
                                              7. Applied rewrites66.3%

                                                \[\leadsto \frac{\sin th}{\frac{\color{blue}{\sin kx}}{\sin ky}} \]
                                            3. Recombined 3 regimes into one program.
                                            4. Final simplification50.1%

                                              \[\leadsto \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.02:\\ \;\;\;\;\left(2 \cdot \left(\left(\sin th \cdot ky\right) \cdot \sqrt{0.5}\right)\right) \cdot \sqrt{{\left(1 - \cos \left(2 \cdot kx\right)\right)}^{-1}}\\ \mathbf{elif}\;\sin kx \leq 4 \cdot 10^{-72}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th}{\frac{\sin kx}{\sin ky}}\\ \end{array} \]
                                            5. Add Preprocessing

                                            Alternative 24: 47.2% accurate, 1.2× speedup?

                                            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.02:\\ \;\;\;\;\left(2 \cdot \left(\left(\sin th \cdot ky\right) \cdot \sqrt{0.5}\right)\right) \cdot \sqrt{{\left(1 - \cos \left(2 \cdot kx\right)\right)}^{-1}}\\ \mathbf{elif}\;\sin kx \leq 4 \cdot 10^{-72}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky}{\sin kx} \cdot \sin th\\ \end{array} \end{array} \]
                                            (FPCore (kx ky th)
                                             :precision binary64
                                             (if (<= (sin kx) -0.02)
                                               (*
                                                (* 2.0 (* (* (sin th) ky) (sqrt 0.5)))
                                                (sqrt (pow (- 1.0 (cos (* 2.0 kx))) -1.0)))
                                               (if (<= (sin kx) 4e-72) (sin th) (* (/ (sin ky) (sin kx)) (sin th)))))
                                            double code(double kx, double ky, double th) {
                                            	double tmp;
                                            	if (sin(kx) <= -0.02) {
                                            		tmp = (2.0 * ((sin(th) * ky) * sqrt(0.5))) * sqrt(pow((1.0 - cos((2.0 * kx))), -1.0));
                                            	} else if (sin(kx) <= 4e-72) {
                                            		tmp = sin(th);
                                            	} else {
                                            		tmp = (sin(ky) / sin(kx)) * 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(kx) <= (-0.02d0)) then
                                                    tmp = (2.0d0 * ((sin(th) * ky) * sqrt(0.5d0))) * sqrt(((1.0d0 - cos((2.0d0 * kx))) ** (-1.0d0)))
                                                else if (sin(kx) <= 4d-72) then
                                                    tmp = sin(th)
                                                else
                                                    tmp = (sin(ky) / sin(kx)) * sin(th)
                                                end if
                                                code = tmp
                                            end function
                                            
                                            public static double code(double kx, double ky, double th) {
                                            	double tmp;
                                            	if (Math.sin(kx) <= -0.02) {
                                            		tmp = (2.0 * ((Math.sin(th) * ky) * Math.sqrt(0.5))) * Math.sqrt(Math.pow((1.0 - Math.cos((2.0 * kx))), -1.0));
                                            	} else if (Math.sin(kx) <= 4e-72) {
                                            		tmp = Math.sin(th);
                                            	} else {
                                            		tmp = (Math.sin(ky) / Math.sin(kx)) * Math.sin(th);
                                            	}
                                            	return tmp;
                                            }
                                            
                                            def code(kx, ky, th):
                                            	tmp = 0
                                            	if math.sin(kx) <= -0.02:
                                            		tmp = (2.0 * ((math.sin(th) * ky) * math.sqrt(0.5))) * math.sqrt(math.pow((1.0 - math.cos((2.0 * kx))), -1.0))
                                            	elif math.sin(kx) <= 4e-72:
                                            		tmp = math.sin(th)
                                            	else:
                                            		tmp = (math.sin(ky) / math.sin(kx)) * math.sin(th)
                                            	return tmp
                                            
                                            function code(kx, ky, th)
                                            	tmp = 0.0
                                            	if (sin(kx) <= -0.02)
                                            		tmp = Float64(Float64(2.0 * Float64(Float64(sin(th) * ky) * sqrt(0.5))) * sqrt((Float64(1.0 - cos(Float64(2.0 * kx))) ^ -1.0)));
                                            	elseif (sin(kx) <= 4e-72)
                                            		tmp = sin(th);
                                            	else
                                            		tmp = Float64(Float64(sin(ky) / sin(kx)) * sin(th));
                                            	end
                                            	return tmp
                                            end
                                            
                                            function tmp_2 = code(kx, ky, th)
                                            	tmp = 0.0;
                                            	if (sin(kx) <= -0.02)
                                            		tmp = (2.0 * ((sin(th) * ky) * sqrt(0.5))) * sqrt(((1.0 - cos((2.0 * kx))) ^ -1.0));
                                            	elseif (sin(kx) <= 4e-72)
                                            		tmp = sin(th);
                                            	else
                                            		tmp = (sin(ky) / sin(kx)) * sin(th);
                                            	end
                                            	tmp_2 = tmp;
                                            end
                                            
                                            code[kx_, ky_, th_] := If[LessEqual[N[Sin[kx], $MachinePrecision], -0.02], N[(N[(2.0 * N[(N[(N[Sin[th], $MachinePrecision] * ky), $MachinePrecision] * N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[Power[N[(1.0 - N[Cos[N[(2.0 * kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[kx], $MachinePrecision], 4e-72], N[Sin[th], $MachinePrecision], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]]]
                                            
                                            \begin{array}{l}
                                            
                                            \\
                                            \begin{array}{l}
                                            \mathbf{if}\;\sin kx \leq -0.02:\\
                                            \;\;\;\;\left(2 \cdot \left(\left(\sin th \cdot ky\right) \cdot \sqrt{0.5}\right)\right) \cdot \sqrt{{\left(1 - \cos \left(2 \cdot kx\right)\right)}^{-1}}\\
                                            
                                            \mathbf{elif}\;\sin kx \leq 4 \cdot 10^{-72}:\\
                                            \;\;\;\;\sin th\\
                                            
                                            \mathbf{else}:\\
                                            \;\;\;\;\frac{\sin ky}{\sin kx} \cdot \sin th\\
                                            
                                            
                                            \end{array}
                                            \end{array}
                                            
                                            Derivation
                                            1. Split input into 3 regimes
                                            2. if (sin.f64 kx) < -0.0200000000000000004

                                              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-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-sin.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky} \cdot \sin ky + {\sin kx}^{2}}} \cdot \sin th \]
                                                7. lift-sin.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \color{blue}{\sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
                                                8. sin-multN/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2}} + {\sin kx}^{2}}} \cdot \sin th \]
                                                9. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
                                                10. unpow2N/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 \]
                                                11. 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 \]
                                                12. 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 \]
                                                13. 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 \]
                                                14. 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 \]
                                                15. 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 \]
                                                16. 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 \]
                                                17. 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 \]
                                              4. Applied rewrites99.3%

                                                \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}}} \cdot \sin th \]
                                              5. Taylor expanded in ky around 0

                                                \[\leadsto \color{blue}{2 \cdot \left(\left(ky \cdot \left(\sin th \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}}\right)} \]
                                              6. Step-by-step derivation
                                                1. associate-*r*N/A

                                                  \[\leadsto \color{blue}{\left(2 \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{\frac{1}{2}}\right)\right)\right) \cdot \sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}}} \]
                                                2. lower-*.f64N/A

                                                  \[\leadsto \color{blue}{\left(2 \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{\frac{1}{2}}\right)\right)\right) \cdot \sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}}} \]
                                                3. lower-*.f64N/A

                                                  \[\leadsto \color{blue}{\left(2 \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{\frac{1}{2}}\right)\right)\right)} \cdot \sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}} \]
                                                4. associate-*r*N/A

                                                  \[\leadsto \left(2 \cdot \color{blue}{\left(\left(ky \cdot \sin th\right) \cdot \sqrt{\frac{1}{2}}\right)}\right) \cdot \sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}} \]
                                                5. lower-*.f64N/A

                                                  \[\leadsto \left(2 \cdot \color{blue}{\left(\left(ky \cdot \sin th\right) \cdot \sqrt{\frac{1}{2}}\right)}\right) \cdot \sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}} \]
                                                6. *-commutativeN/A

                                                  \[\leadsto \left(2 \cdot \left(\color{blue}{\left(\sin th \cdot ky\right)} \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}} \]
                                                7. lower-*.f64N/A

                                                  \[\leadsto \left(2 \cdot \left(\color{blue}{\left(\sin th \cdot ky\right)} \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}} \]
                                                8. lower-sin.f64N/A

                                                  \[\leadsto \left(2 \cdot \left(\left(\color{blue}{\sin th} \cdot ky\right) \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}} \]
                                                9. lower-sqrt.f64N/A

                                                  \[\leadsto \left(2 \cdot \left(\left(\sin th \cdot ky\right) \cdot \color{blue}{\sqrt{\frac{1}{2}}}\right)\right) \cdot \sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}} \]
                                                10. lower-sqrt.f64N/A

                                                  \[\leadsto \left(2 \cdot \left(\left(\sin th \cdot ky\right) \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \color{blue}{\sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}}} \]
                                                11. lower-/.f64N/A

                                                  \[\leadsto \left(2 \cdot \left(\left(\sin th \cdot ky\right) \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{\color{blue}{\frac{1}{1 - \cos \left(2 \cdot kx\right)}}} \]
                                                12. lower--.f64N/A

                                                  \[\leadsto \left(2 \cdot \left(\left(\sin th \cdot ky\right) \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{\frac{1}{\color{blue}{1 - \cos \left(2 \cdot kx\right)}}} \]
                                                13. lower-cos.f64N/A

                                                  \[\leadsto \left(2 \cdot \left(\left(\sin th \cdot ky\right) \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{\frac{1}{1 - \color{blue}{\cos \left(2 \cdot kx\right)}}} \]
                                                14. lower-*.f6445.0

                                                  \[\leadsto \left(2 \cdot \left(\left(\sin th \cdot ky\right) \cdot \sqrt{0.5}\right)\right) \cdot \sqrt{\frac{1}{1 - \cos \color{blue}{\left(2 \cdot kx\right)}}} \]
                                              7. Applied rewrites45.0%

                                                \[\leadsto \color{blue}{\left(2 \cdot \left(\left(\sin th \cdot ky\right) \cdot \sqrt{0.5}\right)\right) \cdot \sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}}} \]

                                              if -0.0200000000000000004 < (sin.f64 kx) < 3.9999999999999999e-72

                                              1. Initial program 84.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}{\sin th} \]
                                              4. Step-by-step derivation
                                                1. lower-sin.f6443.5

                                                  \[\leadsto \color{blue}{\sin th} \]
                                              5. Applied rewrites43.5%

                                                \[\leadsto \color{blue}{\sin th} \]

                                              if 3.9999999999999999e-72 < (sin.f64 kx)

                                              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}{\color{blue}{\sin kx}} \cdot \sin th \]
                                              4. Step-by-step derivation
                                                1. lower-sin.f6466.3

                                                  \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
                                              5. Applied rewrites66.3%

                                                \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
                                            3. Recombined 3 regimes into one program.
                                            4. Final simplification50.1%

                                              \[\leadsto \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.02:\\ \;\;\;\;\left(2 \cdot \left(\left(\sin th \cdot ky\right) \cdot \sqrt{0.5}\right)\right) \cdot \sqrt{{\left(1 - \cos \left(2 \cdot kx\right)\right)}^{-1}}\\ \mathbf{elif}\;\sin kx \leq 4 \cdot 10^{-72}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky}{\sin kx} \cdot \sin th\\ \end{array} \]
                                            5. Add Preprocessing

                                            Alternative 25: 99.6% accurate, 1.2× speedup?

                                            \[\begin{array}{l} \\ \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin ky \end{array} \]
                                            (FPCore (kx ky th)
                                             :precision binary64
                                             (* (/ (sin th) (hypot (sin ky) (sin kx))) (sin ky)))
                                            double code(double kx, double ky, double th) {
                                            	return (sin(th) / hypot(sin(ky), sin(kx))) * sin(ky);
                                            }
                                            
                                            public static double code(double kx, double ky, double th) {
                                            	return (Math.sin(th) / Math.hypot(Math.sin(ky), Math.sin(kx))) * Math.sin(ky);
                                            }
                                            
                                            def code(kx, ky, th):
                                            	return (math.sin(th) / math.hypot(math.sin(ky), math.sin(kx))) * math.sin(ky)
                                            
                                            function code(kx, ky, th)
                                            	return Float64(Float64(sin(th) / hypot(sin(ky), sin(kx))) * sin(ky))
                                            end
                                            
                                            function tmp = code(kx, ky, th)
                                            	tmp = (sin(th) / hypot(sin(ky), sin(kx))) * sin(ky);
                                            end
                                            
                                            code[kx_, ky_, th_] := N[(N[(N[Sin[th], $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[Sin[ky], $MachinePrecision]), $MachinePrecision]
                                            
                                            \begin{array}{l}
                                            
                                            \\
                                            \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin ky
                                            \end{array}
                                            
                                            Derivation
                                            1. Initial program 92.7%

                                              \[\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-/.f6492.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.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. Add Preprocessing

                                            Alternative 26: 74.3% accurate, 1.4× speedup?

                                            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 0.0012:\\ \;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\mathsf{fma}\left(-0.16666666666666666, ky \cdot ky, 1\right) \cdot ky}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th}{\frac{\sqrt{2 \cdot \left(\left(1 - \cos \left(2 \cdot ky\right)\right) + \left(1 - \cos \left(2 \cdot kx\right)\right)\right)} \cdot 0.5}{\sin ky}}\\ \end{array} \end{array} \]
                                            (FPCore (kx ky th)
                                             :precision binary64
                                             (if (<= ky 0.0012)
                                               (/
                                                (sin th)
                                                (/
                                                 (hypot (sin ky) (sin kx))
                                                 (* (fma -0.16666666666666666 (* ky ky) 1.0) ky)))
                                               (/
                                                (sin th)
                                                (/
                                                 (*
                                                  (sqrt (* 2.0 (+ (- 1.0 (cos (* 2.0 ky))) (- 1.0 (cos (* 2.0 kx))))))
                                                  0.5)
                                                 (sin ky)))))
                                            double code(double kx, double ky, double th) {
                                            	double tmp;
                                            	if (ky <= 0.0012) {
                                            		tmp = sin(th) / (hypot(sin(ky), sin(kx)) / (fma(-0.16666666666666666, (ky * ky), 1.0) * ky));
                                            	} else {
                                            		tmp = sin(th) / ((sqrt((2.0 * ((1.0 - cos((2.0 * ky))) + (1.0 - cos((2.0 * kx)))))) * 0.5) / sin(ky));
                                            	}
                                            	return tmp;
                                            }
                                            
                                            function code(kx, ky, th)
                                            	tmp = 0.0
                                            	if (ky <= 0.0012)
                                            		tmp = Float64(sin(th) / Float64(hypot(sin(ky), sin(kx)) / Float64(fma(-0.16666666666666666, Float64(ky * ky), 1.0) * ky)));
                                            	else
                                            		tmp = Float64(sin(th) / Float64(Float64(sqrt(Float64(2.0 * Float64(Float64(1.0 - cos(Float64(2.0 * ky))) + Float64(1.0 - cos(Float64(2.0 * kx)))))) * 0.5) / sin(ky)));
                                            	end
                                            	return tmp
                                            end
                                            
                                            code[kx_, ky_, th_] := If[LessEqual[ky, 0.0012], N[(N[Sin[th], $MachinePrecision] / N[(N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision] / N[(N[(-0.16666666666666666 * N[(ky * ky), $MachinePrecision] + 1.0), $MachinePrecision] * ky), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[th], $MachinePrecision] / N[(N[(N[Sqrt[N[(2.0 * N[(N[(1.0 - N[Cos[N[(2.0 * ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(1.0 - N[Cos[N[(2.0 * kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision] / N[Sin[ky], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
                                            
                                            \begin{array}{l}
                                            
                                            \\
                                            \begin{array}{l}
                                            \mathbf{if}\;ky \leq 0.0012:\\
                                            \;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\mathsf{fma}\left(-0.16666666666666666, ky \cdot ky, 1\right) \cdot ky}}\\
                                            
                                            \mathbf{else}:\\
                                            \;\;\;\;\frac{\sin th}{\frac{\sqrt{2 \cdot \left(\left(1 - \cos \left(2 \cdot ky\right)\right) + \left(1 - \cos \left(2 \cdot kx\right)\right)\right)} \cdot 0.5}{\sin ky}}\\
                                            
                                            
                                            \end{array}
                                            \end{array}
                                            
                                            Derivation
                                            1. Split input into 2 regimes
                                            2. if ky < 0.00119999999999999989

                                              1. Initial program 90.6%

                                                \[\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. *-commutativeN/A

                                                  \[\leadsto \color{blue}{\sin th \cdot \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                                                3. lift-/.f64N/A

                                                  \[\leadsto \sin th \cdot \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                                                4. clear-numN/A

                                                  \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                5. un-div-invN/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                6. lower-/.f64N/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                7. lower-/.f6490.7

                                                  \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                8. lift-sqrt.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}}{\sin ky}} \]
                                                9. lift-+.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}}{\sin ky}} \]
                                                10. +-commutativeN/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}}{\sin ky}} \]
                                                11. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin ky}^{2}} + {\sin kx}^{2}}}{\sin ky}} \]
                                                12. unpow2N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}}{\sin ky}} \]
                                                13. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\sin ky \cdot \sin ky + \color{blue}{{\sin kx}^{2}}}}{\sin ky}} \]
                                                14. unpow2N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}}{\sin ky}} \]
                                                15. lower-hypot.f6499.8

                                                  \[\leadsto \frac{\sin th}{\frac{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{\sin ky}} \]
                                              4. Applied rewrites99.8%

                                                \[\leadsto \color{blue}{\frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin ky}}} \]
                                              5. Taylor expanded in ky around 0

                                                \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{ky \cdot \left(1 + \frac{-1}{6} \cdot {ky}^{2}\right)}}} \]
                                              6. Step-by-step derivation
                                                1. *-commutativeN/A

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}}} \]
                                                2. lower-*.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}}} \]
                                                3. +-commutativeN/A

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)} \cdot ky}} \]
                                                4. lower-fma.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{\mathsf{fma}\left(\frac{-1}{6}, {ky}^{2}, 1\right)} \cdot ky}} \]
                                                5. unpow2N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\mathsf{fma}\left(\frac{-1}{6}, \color{blue}{ky \cdot ky}, 1\right) \cdot ky}} \]
                                                6. lower-*.f6469.2

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\mathsf{fma}\left(-0.16666666666666666, \color{blue}{ky \cdot ky}, 1\right) \cdot ky}} \]
                                              7. Applied rewrites69.2%

                                                \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{\mathsf{fma}\left(-0.16666666666666666, ky \cdot ky, 1\right) \cdot ky}}} \]

                                              if 0.00119999999999999989 < ky

                                              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-*.f64N/A

                                                  \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th} \]
                                                2. *-commutativeN/A

                                                  \[\leadsto \color{blue}{\sin th \cdot \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                                                3. lift-/.f64N/A

                                                  \[\leadsto \sin th \cdot \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                                                4. clear-numN/A

                                                  \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                5. un-div-invN/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                6. lower-/.f64N/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                7. lower-/.f6499.7

                                                  \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                8. lift-sqrt.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}}{\sin ky}} \]
                                                9. lift-+.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}}{\sin ky}} \]
                                                10. +-commutativeN/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}}{\sin ky}} \]
                                                11. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin ky}^{2}} + {\sin kx}^{2}}}{\sin ky}} \]
                                                12. unpow2N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}}{\sin ky}} \]
                                                13. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\sin ky \cdot \sin ky + \color{blue}{{\sin kx}^{2}}}}{\sin ky}} \]
                                                14. unpow2N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}}{\sin ky}} \]
                                                15. lower-hypot.f6499.6

                                                  \[\leadsto \frac{\sin th}{\frac{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{\sin ky}} \]
                                              4. Applied rewrites99.6%

                                                \[\leadsto \color{blue}{\frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin ky}}} \]
                                              5. Applied rewrites99.0%

                                                \[\leadsto \frac{\sin th}{\frac{\color{blue}{\sqrt{2 \cdot \left(\left(1 - \cos \left(2 \cdot ky\right)\right) + \left(1 - \cos \left(2 \cdot kx\right)\right)\right)} \cdot 0.5}}{\sin ky}} \]
                                            3. Recombined 2 regimes into one program.
                                            4. Add Preprocessing

                                            Alternative 27: 74.3% accurate, 1.4× speedup?

                                            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 0.0012:\\ \;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\mathsf{fma}\left(-0.16666666666666666, ky \cdot ky, 1\right) \cdot ky}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky \cdot \sin th}{\sqrt{2 \cdot \left(\left(1 - \cos \left(2 \cdot ky\right)\right) + \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}} \cdot 2\\ \end{array} \end{array} \]
                                            (FPCore (kx ky th)
                                             :precision binary64
                                             (if (<= ky 0.0012)
                                               (/
                                                (sin th)
                                                (/
                                                 (hypot (sin ky) (sin kx))
                                                 (* (fma -0.16666666666666666 (* ky ky) 1.0) ky)))
                                               (*
                                                (/
                                                 (* (sin ky) (sin th))
                                                 (sqrt (* 2.0 (+ (- 1.0 (cos (* 2.0 ky))) (- 1.0 (cos (* 2.0 kx)))))))
                                                2.0)))
                                            double code(double kx, double ky, double th) {
                                            	double tmp;
                                            	if (ky <= 0.0012) {
                                            		tmp = sin(th) / (hypot(sin(ky), sin(kx)) / (fma(-0.16666666666666666, (ky * ky), 1.0) * ky));
                                            	} else {
                                            		tmp = ((sin(ky) * sin(th)) / sqrt((2.0 * ((1.0 - cos((2.0 * ky))) + (1.0 - cos((2.0 * kx))))))) * 2.0;
                                            	}
                                            	return tmp;
                                            }
                                            
                                            function code(kx, ky, th)
                                            	tmp = 0.0
                                            	if (ky <= 0.0012)
                                            		tmp = Float64(sin(th) / Float64(hypot(sin(ky), sin(kx)) / Float64(fma(-0.16666666666666666, Float64(ky * ky), 1.0) * ky)));
                                            	else
                                            		tmp = Float64(Float64(Float64(sin(ky) * sin(th)) / sqrt(Float64(2.0 * Float64(Float64(1.0 - cos(Float64(2.0 * ky))) + Float64(1.0 - cos(Float64(2.0 * kx))))))) * 2.0);
                                            	end
                                            	return tmp
                                            end
                                            
                                            code[kx_, ky_, th_] := If[LessEqual[ky, 0.0012], N[(N[Sin[th], $MachinePrecision] / N[(N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision] / N[(N[(-0.16666666666666666 * N[(ky * ky), $MachinePrecision] + 1.0), $MachinePrecision] * ky), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Sin[ky], $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(2.0 * N[(N[(1.0 - N[Cos[N[(2.0 * ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(1.0 - N[Cos[N[(2.0 * kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]]
                                            
                                            \begin{array}{l}
                                            
                                            \\
                                            \begin{array}{l}
                                            \mathbf{if}\;ky \leq 0.0012:\\
                                            \;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\mathsf{fma}\left(-0.16666666666666666, ky \cdot ky, 1\right) \cdot ky}}\\
                                            
                                            \mathbf{else}:\\
                                            \;\;\;\;\frac{\sin ky \cdot \sin th}{\sqrt{2 \cdot \left(\left(1 - \cos \left(2 \cdot ky\right)\right) + \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}} \cdot 2\\
                                            
                                            
                                            \end{array}
                                            \end{array}
                                            
                                            Derivation
                                            1. Split input into 2 regimes
                                            2. if ky < 0.00119999999999999989

                                              1. Initial program 90.6%

                                                \[\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. *-commutativeN/A

                                                  \[\leadsto \color{blue}{\sin th \cdot \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                                                3. lift-/.f64N/A

                                                  \[\leadsto \sin th \cdot \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                                                4. clear-numN/A

                                                  \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                5. un-div-invN/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                6. lower-/.f64N/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                7. lower-/.f6490.7

                                                  \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                8. lift-sqrt.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}}{\sin ky}} \]
                                                9. lift-+.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}}{\sin ky}} \]
                                                10. +-commutativeN/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}}{\sin ky}} \]
                                                11. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin ky}^{2}} + {\sin kx}^{2}}}{\sin ky}} \]
                                                12. unpow2N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}}{\sin ky}} \]
                                                13. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\sin ky \cdot \sin ky + \color{blue}{{\sin kx}^{2}}}}{\sin ky}} \]
                                                14. unpow2N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}}{\sin ky}} \]
                                                15. lower-hypot.f6499.8

                                                  \[\leadsto \frac{\sin th}{\frac{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{\sin ky}} \]
                                              4. Applied rewrites99.8%

                                                \[\leadsto \color{blue}{\frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin ky}}} \]
                                              5. Taylor expanded in ky around 0

                                                \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{ky \cdot \left(1 + \frac{-1}{6} \cdot {ky}^{2}\right)}}} \]
                                              6. Step-by-step derivation
                                                1. *-commutativeN/A

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}}} \]
                                                2. lower-*.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}}} \]
                                                3. +-commutativeN/A

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)} \cdot ky}} \]
                                                4. lower-fma.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{\mathsf{fma}\left(\frac{-1}{6}, {ky}^{2}, 1\right)} \cdot ky}} \]
                                                5. unpow2N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\mathsf{fma}\left(\frac{-1}{6}, \color{blue}{ky \cdot ky}, 1\right) \cdot ky}} \]
                                                6. lower-*.f6469.2

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\mathsf{fma}\left(-0.16666666666666666, \color{blue}{ky \cdot ky}, 1\right) \cdot ky}} \]
                                              7. Applied rewrites69.2%

                                                \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{\mathsf{fma}\left(-0.16666666666666666, ky \cdot ky, 1\right) \cdot ky}}} \]

                                              if 0.00119999999999999989 < ky

                                              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-*.f64N/A

                                                  \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th} \]
                                                2. *-commutativeN/A

                                                  \[\leadsto \color{blue}{\sin th \cdot \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                                                3. lift-/.f64N/A

                                                  \[\leadsto \sin th \cdot \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                                                4. clear-numN/A

                                                  \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                5. un-div-invN/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                6. lower-/.f64N/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                7. lower-/.f6499.7

                                                  \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                8. lift-sqrt.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}}{\sin ky}} \]
                                                9. lift-+.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}}{\sin ky}} \]
                                                10. +-commutativeN/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}}{\sin ky}} \]
                                                11. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin ky}^{2}} + {\sin kx}^{2}}}{\sin ky}} \]
                                                12. unpow2N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}}{\sin ky}} \]
                                                13. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\sin ky \cdot \sin ky + \color{blue}{{\sin kx}^{2}}}}{\sin ky}} \]
                                                14. unpow2N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}}{\sin ky}} \]
                                                15. lower-hypot.f6499.6

                                                  \[\leadsto \frac{\sin th}{\frac{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{\sin ky}} \]
                                              4. Applied rewrites99.6%

                                                \[\leadsto \color{blue}{\frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin ky}}} \]
                                              5. Applied rewrites98.9%

                                                \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{2 \cdot \left(\left(1 - \cos \left(2 \cdot ky\right)\right) + \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}} \cdot 2} \]
                                            3. Recombined 2 regimes into one program.
                                            4. Add Preprocessing

                                            Alternative 28: 74.3% accurate, 1.4× speedup?

                                            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 0.0012:\\ \;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\mathsf{fma}\left(-0.16666666666666666, ky \cdot ky, 1\right) \cdot ky}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky \cdot 2}{\sqrt{2 \cdot \left(\left(1 - \cos \left(2 \cdot ky\right)\right) + \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}} \cdot \sin th\\ \end{array} \end{array} \]
                                            (FPCore (kx ky th)
                                             :precision binary64
                                             (if (<= ky 0.0012)
                                               (/
                                                (sin th)
                                                (/
                                                 (hypot (sin ky) (sin kx))
                                                 (* (fma -0.16666666666666666 (* ky ky) 1.0) ky)))
                                               (*
                                                (/
                                                 (* (sin ky) 2.0)
                                                 (sqrt (* 2.0 (+ (- 1.0 (cos (* 2.0 ky))) (- 1.0 (cos (* 2.0 kx)))))))
                                                (sin th))))
                                            double code(double kx, double ky, double th) {
                                            	double tmp;
                                            	if (ky <= 0.0012) {
                                            		tmp = sin(th) / (hypot(sin(ky), sin(kx)) / (fma(-0.16666666666666666, (ky * ky), 1.0) * ky));
                                            	} else {
                                            		tmp = ((sin(ky) * 2.0) / sqrt((2.0 * ((1.0 - cos((2.0 * ky))) + (1.0 - cos((2.0 * kx))))))) * sin(th);
                                            	}
                                            	return tmp;
                                            }
                                            
                                            function code(kx, ky, th)
                                            	tmp = 0.0
                                            	if (ky <= 0.0012)
                                            		tmp = Float64(sin(th) / Float64(hypot(sin(ky), sin(kx)) / Float64(fma(-0.16666666666666666, Float64(ky * ky), 1.0) * ky)));
                                            	else
                                            		tmp = Float64(Float64(Float64(sin(ky) * 2.0) / sqrt(Float64(2.0 * Float64(Float64(1.0 - cos(Float64(2.0 * ky))) + Float64(1.0 - cos(Float64(2.0 * kx))))))) * sin(th));
                                            	end
                                            	return tmp
                                            end
                                            
                                            code[kx_, ky_, th_] := If[LessEqual[ky, 0.0012], N[(N[Sin[th], $MachinePrecision] / N[(N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision] / N[(N[(-0.16666666666666666 * N[(ky * ky), $MachinePrecision] + 1.0), $MachinePrecision] * ky), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Sin[ky], $MachinePrecision] * 2.0), $MachinePrecision] / N[Sqrt[N[(2.0 * N[(N[(1.0 - N[Cos[N[(2.0 * ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(1.0 - N[Cos[N[(2.0 * kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]]
                                            
                                            \begin{array}{l}
                                            
                                            \\
                                            \begin{array}{l}
                                            \mathbf{if}\;ky \leq 0.0012:\\
                                            \;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\mathsf{fma}\left(-0.16666666666666666, ky \cdot ky, 1\right) \cdot ky}}\\
                                            
                                            \mathbf{else}:\\
                                            \;\;\;\;\frac{\sin ky \cdot 2}{\sqrt{2 \cdot \left(\left(1 - \cos \left(2 \cdot ky\right)\right) + \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}} \cdot \sin th\\
                                            
                                            
                                            \end{array}
                                            \end{array}
                                            
                                            Derivation
                                            1. Split input into 2 regimes
                                            2. if ky < 0.00119999999999999989

                                              1. Initial program 90.6%

                                                \[\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. *-commutativeN/A

                                                  \[\leadsto \color{blue}{\sin th \cdot \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                                                3. lift-/.f64N/A

                                                  \[\leadsto \sin th \cdot \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                                                4. clear-numN/A

                                                  \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                5. un-div-invN/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                6. lower-/.f64N/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                7. lower-/.f6490.7

                                                  \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                8. lift-sqrt.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}}{\sin ky}} \]
                                                9. lift-+.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}}{\sin ky}} \]
                                                10. +-commutativeN/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}}{\sin ky}} \]
                                                11. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin ky}^{2}} + {\sin kx}^{2}}}{\sin ky}} \]
                                                12. unpow2N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}}{\sin ky}} \]
                                                13. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\sin ky \cdot \sin ky + \color{blue}{{\sin kx}^{2}}}}{\sin ky}} \]
                                                14. unpow2N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}}{\sin ky}} \]
                                                15. lower-hypot.f6499.8

                                                  \[\leadsto \frac{\sin th}{\frac{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{\sin ky}} \]
                                              4. Applied rewrites99.8%

                                                \[\leadsto \color{blue}{\frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin ky}}} \]
                                              5. Taylor expanded in ky around 0

                                                \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{ky \cdot \left(1 + \frac{-1}{6} \cdot {ky}^{2}\right)}}} \]
                                              6. Step-by-step derivation
                                                1. *-commutativeN/A

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}}} \]
                                                2. lower-*.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}}} \]
                                                3. +-commutativeN/A

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)} \cdot ky}} \]
                                                4. lower-fma.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{\mathsf{fma}\left(\frac{-1}{6}, {ky}^{2}, 1\right)} \cdot ky}} \]
                                                5. unpow2N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\mathsf{fma}\left(\frac{-1}{6}, \color{blue}{ky \cdot ky}, 1\right) \cdot ky}} \]
                                                6. lower-*.f6469.2

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\mathsf{fma}\left(-0.16666666666666666, \color{blue}{ky \cdot ky}, 1\right) \cdot ky}} \]
                                              7. Applied rewrites69.2%

                                                \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{\mathsf{fma}\left(-0.16666666666666666, ky \cdot ky, 1\right) \cdot ky}}} \]

                                              if 0.00119999999999999989 < ky

                                              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-sin.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky} \cdot \sin ky + {\sin kx}^{2}}} \cdot \sin th \]
                                                7. lift-sin.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \color{blue}{\sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
                                                8. sin-multN/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2}} + {\sin kx}^{2}}} \cdot \sin th \]
                                                9. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
                                                10. unpow2N/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 \]
                                                11. 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 \]
                                                12. 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 \]
                                                13. 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 \]
                                                14. 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 \]
                                                15. 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 \]
                                                16. 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 \]
                                                17. 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 \]
                                              4. Applied rewrites98.9%

                                                \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}}} \cdot \sin th \]
                                              5. Applied rewrites98.9%

                                                \[\leadsto \color{blue}{\frac{\sin ky \cdot 2}{\sqrt{2 \cdot \left(\left(1 - \cos \left(2 \cdot ky\right)\right) + \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}} \cdot \sin th \]
                                            3. Recombined 2 regimes into one program.
                                            4. Add Preprocessing

                                            Alternative 29: 74.3% accurate, 1.4× speedup?

                                            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 0.0012:\\ \;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\mathsf{fma}\left(-0.16666666666666666, ky \cdot ky, 1\right) \cdot ky}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky}{\sqrt{2 \cdot \left(1 - \left(\cos \left(2 \cdot kx\right) - \left(1 - \cos \left(2 \cdot ky\right)\right)\right)\right)} \cdot 0.5} \cdot \sin th\\ \end{array} \end{array} \]
                                            (FPCore (kx ky th)
                                             :precision binary64
                                             (if (<= ky 0.0012)
                                               (/
                                                (sin th)
                                                (/
                                                 (hypot (sin ky) (sin kx))
                                                 (* (fma -0.16666666666666666 (* ky ky) 1.0) ky)))
                                               (*
                                                (/
                                                 (sin ky)
                                                 (*
                                                  (sqrt (* 2.0 (- 1.0 (- (cos (* 2.0 kx)) (- 1.0 (cos (* 2.0 ky)))))))
                                                  0.5))
                                                (sin th))))
                                            double code(double kx, double ky, double th) {
                                            	double tmp;
                                            	if (ky <= 0.0012) {
                                            		tmp = sin(th) / (hypot(sin(ky), sin(kx)) / (fma(-0.16666666666666666, (ky * ky), 1.0) * ky));
                                            	} else {
                                            		tmp = (sin(ky) / (sqrt((2.0 * (1.0 - (cos((2.0 * kx)) - (1.0 - cos((2.0 * ky))))))) * 0.5)) * sin(th);
                                            	}
                                            	return tmp;
                                            }
                                            
                                            function code(kx, ky, th)
                                            	tmp = 0.0
                                            	if (ky <= 0.0012)
                                            		tmp = Float64(sin(th) / Float64(hypot(sin(ky), sin(kx)) / Float64(fma(-0.16666666666666666, Float64(ky * ky), 1.0) * ky)));
                                            	else
                                            		tmp = Float64(Float64(sin(ky) / Float64(sqrt(Float64(2.0 * Float64(1.0 - Float64(cos(Float64(2.0 * kx)) - Float64(1.0 - cos(Float64(2.0 * ky))))))) * 0.5)) * sin(th));
                                            	end
                                            	return tmp
                                            end
                                            
                                            code[kx_, ky_, th_] := If[LessEqual[ky, 0.0012], N[(N[Sin[th], $MachinePrecision] / N[(N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision] / N[(N[(-0.16666666666666666 * N[(ky * ky), $MachinePrecision] + 1.0), $MachinePrecision] * ky), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sin[ky], $MachinePrecision] / N[(N[Sqrt[N[(2.0 * N[(1.0 - N[(N[Cos[N[(2.0 * kx), $MachinePrecision]], $MachinePrecision] - N[(1.0 - N[Cos[N[(2.0 * ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]]
                                            
                                            \begin{array}{l}
                                            
                                            \\
                                            \begin{array}{l}
                                            \mathbf{if}\;ky \leq 0.0012:\\
                                            \;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\mathsf{fma}\left(-0.16666666666666666, ky \cdot ky, 1\right) \cdot ky}}\\
                                            
                                            \mathbf{else}:\\
                                            \;\;\;\;\frac{\sin ky}{\sqrt{2 \cdot \left(1 - \left(\cos \left(2 \cdot kx\right) - \left(1 - \cos \left(2 \cdot ky\right)\right)\right)\right)} \cdot 0.5} \cdot \sin th\\
                                            
                                            
                                            \end{array}
                                            \end{array}
                                            
                                            Derivation
                                            1. Split input into 2 regimes
                                            2. if ky < 0.00119999999999999989

                                              1. Initial program 90.6%

                                                \[\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. *-commutativeN/A

                                                  \[\leadsto \color{blue}{\sin th \cdot \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                                                3. lift-/.f64N/A

                                                  \[\leadsto \sin th \cdot \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                                                4. clear-numN/A

                                                  \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                5. un-div-invN/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                6. lower-/.f64N/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                7. lower-/.f6490.7

                                                  \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                8. lift-sqrt.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}}{\sin ky}} \]
                                                9. lift-+.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}}{\sin ky}} \]
                                                10. +-commutativeN/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}}{\sin ky}} \]
                                                11. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin ky}^{2}} + {\sin kx}^{2}}}{\sin ky}} \]
                                                12. unpow2N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}}{\sin ky}} \]
                                                13. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\sin ky \cdot \sin ky + \color{blue}{{\sin kx}^{2}}}}{\sin ky}} \]
                                                14. unpow2N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}}{\sin ky}} \]
                                                15. lower-hypot.f6499.8

                                                  \[\leadsto \frac{\sin th}{\frac{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{\sin ky}} \]
                                              4. Applied rewrites99.8%

                                                \[\leadsto \color{blue}{\frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin ky}}} \]
                                              5. Taylor expanded in ky around 0

                                                \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{ky \cdot \left(1 + \frac{-1}{6} \cdot {ky}^{2}\right)}}} \]
                                              6. Step-by-step derivation
                                                1. *-commutativeN/A

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}}} \]
                                                2. lower-*.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}}} \]
                                                3. +-commutativeN/A

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)} \cdot ky}} \]
                                                4. lower-fma.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{\mathsf{fma}\left(\frac{-1}{6}, {ky}^{2}, 1\right)} \cdot ky}} \]
                                                5. unpow2N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\mathsf{fma}\left(\frac{-1}{6}, \color{blue}{ky \cdot ky}, 1\right) \cdot ky}} \]
                                                6. lower-*.f6469.2

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\mathsf{fma}\left(-0.16666666666666666, \color{blue}{ky \cdot ky}, 1\right) \cdot ky}} \]
                                              7. Applied rewrites69.2%

                                                \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{\mathsf{fma}\left(-0.16666666666666666, ky \cdot ky, 1\right) \cdot ky}}} \]

                                              if 0.00119999999999999989 < ky

                                              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-sin.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky} \cdot \sin ky + {\sin kx}^{2}}} \cdot \sin th \]
                                                7. lift-sin.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \color{blue}{\sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
                                                8. sin-multN/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2}} + {\sin kx}^{2}}} \cdot \sin th \]
                                                9. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
                                                10. unpow2N/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 \]
                                                11. 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 \]
                                                12. 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 \]
                                                13. 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 \]
                                                14. 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 \]
                                                15. 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 \]
                                                16. 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 \]
                                                17. 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 \]
                                              4. Applied rewrites98.9%

                                                \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}}} \cdot \sin th \]
                                              5. Taylor expanded in ky around 0

                                                \[\leadsto \frac{\sin ky}{\frac{\color{blue}{\sqrt{2} \cdot \sqrt{1 - \cos \left(2 \cdot kx\right)}}}{2}} \cdot \sin th \]
                                              6. Step-by-step derivation
                                                1. *-commutativeN/A

                                                  \[\leadsto \frac{\sin ky}{\frac{\color{blue}{\sqrt{1 - \cos \left(2 \cdot kx\right)} \cdot \sqrt{2}}}{2}} \cdot \sin th \]
                                                2. lower-*.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\frac{\color{blue}{\sqrt{1 - \cos \left(2 \cdot kx\right)} \cdot \sqrt{2}}}{2}} \cdot \sin th \]
                                                3. lower-sqrt.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\frac{\color{blue}{\sqrt{1 - \cos \left(2 \cdot kx\right)}} \cdot \sqrt{2}}{2}} \cdot \sin th \]
                                                4. lower--.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\frac{\sqrt{\color{blue}{1 - \cos \left(2 \cdot kx\right)}} \cdot \sqrt{2}}{2}} \cdot \sin th \]
                                                5. lower-cos.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\frac{\sqrt{1 - \color{blue}{\cos \left(2 \cdot kx\right)}} \cdot \sqrt{2}}{2}} \cdot \sin th \]
                                                6. lower-*.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\frac{\sqrt{1 - \cos \color{blue}{\left(2 \cdot kx\right)}} \cdot \sqrt{2}}{2}} \cdot \sin th \]
                                                7. lower-sqrt.f6413.7

                                                  \[\leadsto \frac{\sin ky}{\frac{\sqrt{1 - \cos \left(2 \cdot kx\right)} \cdot \color{blue}{\sqrt{2}}}{2}} \cdot \sin th \]
                                              7. Applied rewrites13.7%

                                                \[\leadsto \frac{\sin ky}{\frac{\color{blue}{\sqrt{1 - \cos \left(2 \cdot kx\right)} \cdot \sqrt{2}}}{2}} \cdot \sin th \]
                                              8. Taylor expanded in kx around inf

                                                \[\leadsto \frac{\sin ky}{\color{blue}{\frac{1}{2} \cdot \sqrt{2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right) + 2 \cdot \left(1 - \cos \left(2 \cdot ky\right)\right)}}} \cdot \sin th \]
                                              9. Step-by-step derivation
                                                1. *-commutativeN/A

                                                  \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right) + 2 \cdot \left(1 - \cos \left(2 \cdot ky\right)\right)} \cdot \frac{1}{2}}} \cdot \sin th \]
                                                2. lower-*.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right) + 2 \cdot \left(1 - \cos \left(2 \cdot ky\right)\right)} \cdot \frac{1}{2}}} \cdot \sin th \]
                                              10. Applied rewrites98.9%

                                                \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{2 \cdot \left(1 - \left(\cos \left(2 \cdot kx\right) - \left(1 - \cos \left(2 \cdot ky\right)\right)\right)\right)} \cdot 0.5}} \cdot \sin th \]
                                            3. Recombined 2 regimes into one program.
                                            4. Add Preprocessing

                                            Alternative 30: 74.3% accurate, 1.4× speedup?

                                            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 0.0012:\\ \;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\mathsf{fma}\left(-0.16666666666666666, ky \cdot ky, 1\right) \cdot ky}}\\ \mathbf{else}:\\ \;\;\;\;\left(\left(2 \cdot \sin ky\right) \cdot \sqrt{\frac{0.5}{1 - \left(\cos \left(2 \cdot kx\right) - \left(1 - \cos \left(2 \cdot ky\right)\right)\right)}}\right) \cdot \sin th\\ \end{array} \end{array} \]
                                            (FPCore (kx ky th)
                                             :precision binary64
                                             (if (<= ky 0.0012)
                                               (/
                                                (sin th)
                                                (/
                                                 (hypot (sin ky) (sin kx))
                                                 (* (fma -0.16666666666666666 (* ky ky) 1.0) ky)))
                                               (*
                                                (*
                                                 (* 2.0 (sin ky))
                                                 (sqrt (/ 0.5 (- 1.0 (- (cos (* 2.0 kx)) (- 1.0 (cos (* 2.0 ky))))))))
                                                (sin th))))
                                            double code(double kx, double ky, double th) {
                                            	double tmp;
                                            	if (ky <= 0.0012) {
                                            		tmp = sin(th) / (hypot(sin(ky), sin(kx)) / (fma(-0.16666666666666666, (ky * ky), 1.0) * ky));
                                            	} else {
                                            		tmp = ((2.0 * sin(ky)) * sqrt((0.5 / (1.0 - (cos((2.0 * kx)) - (1.0 - cos((2.0 * ky)))))))) * sin(th);
                                            	}
                                            	return tmp;
                                            }
                                            
                                            function code(kx, ky, th)
                                            	tmp = 0.0
                                            	if (ky <= 0.0012)
                                            		tmp = Float64(sin(th) / Float64(hypot(sin(ky), sin(kx)) / Float64(fma(-0.16666666666666666, Float64(ky * ky), 1.0) * ky)));
                                            	else
                                            		tmp = Float64(Float64(Float64(2.0 * sin(ky)) * sqrt(Float64(0.5 / Float64(1.0 - Float64(cos(Float64(2.0 * kx)) - Float64(1.0 - cos(Float64(2.0 * ky)))))))) * sin(th));
                                            	end
                                            	return tmp
                                            end
                                            
                                            code[kx_, ky_, th_] := If[LessEqual[ky, 0.0012], N[(N[Sin[th], $MachinePrecision] / N[(N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision] / N[(N[(-0.16666666666666666 * N[(ky * ky), $MachinePrecision] + 1.0), $MachinePrecision] * ky), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(2.0 * N[Sin[ky], $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(0.5 / N[(1.0 - N[(N[Cos[N[(2.0 * kx), $MachinePrecision]], $MachinePrecision] - N[(1.0 - N[Cos[N[(2.0 * ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]]
                                            
                                            \begin{array}{l}
                                            
                                            \\
                                            \begin{array}{l}
                                            \mathbf{if}\;ky \leq 0.0012:\\
                                            \;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\mathsf{fma}\left(-0.16666666666666666, ky \cdot ky, 1\right) \cdot ky}}\\
                                            
                                            \mathbf{else}:\\
                                            \;\;\;\;\left(\left(2 \cdot \sin ky\right) \cdot \sqrt{\frac{0.5}{1 - \left(\cos \left(2 \cdot kx\right) - \left(1 - \cos \left(2 \cdot ky\right)\right)\right)}}\right) \cdot \sin th\\
                                            
                                            
                                            \end{array}
                                            \end{array}
                                            
                                            Derivation
                                            1. Split input into 2 regimes
                                            2. if ky < 0.00119999999999999989

                                              1. Initial program 90.6%

                                                \[\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. *-commutativeN/A

                                                  \[\leadsto \color{blue}{\sin th \cdot \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                                                3. lift-/.f64N/A

                                                  \[\leadsto \sin th \cdot \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                                                4. clear-numN/A

                                                  \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                5. un-div-invN/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                6. lower-/.f64N/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                7. lower-/.f6490.7

                                                  \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                8. lift-sqrt.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}}{\sin ky}} \]
                                                9. lift-+.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}}{\sin ky}} \]
                                                10. +-commutativeN/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}}{\sin ky}} \]
                                                11. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin ky}^{2}} + {\sin kx}^{2}}}{\sin ky}} \]
                                                12. unpow2N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}}{\sin ky}} \]
                                                13. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\sin ky \cdot \sin ky + \color{blue}{{\sin kx}^{2}}}}{\sin ky}} \]
                                                14. unpow2N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}}{\sin ky}} \]
                                                15. lower-hypot.f6499.8

                                                  \[\leadsto \frac{\sin th}{\frac{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{\sin ky}} \]
                                              4. Applied rewrites99.8%

                                                \[\leadsto \color{blue}{\frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin ky}}} \]
                                              5. Taylor expanded in ky around 0

                                                \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{ky \cdot \left(1 + \frac{-1}{6} \cdot {ky}^{2}\right)}}} \]
                                              6. Step-by-step derivation
                                                1. *-commutativeN/A

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}}} \]
                                                2. lower-*.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}}} \]
                                                3. +-commutativeN/A

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)} \cdot ky}} \]
                                                4. lower-fma.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{\mathsf{fma}\left(\frac{-1}{6}, {ky}^{2}, 1\right)} \cdot ky}} \]
                                                5. unpow2N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\mathsf{fma}\left(\frac{-1}{6}, \color{blue}{ky \cdot ky}, 1\right) \cdot ky}} \]
                                                6. lower-*.f6469.2

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\mathsf{fma}\left(-0.16666666666666666, \color{blue}{ky \cdot ky}, 1\right) \cdot ky}} \]
                                              7. Applied rewrites69.2%

                                                \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{\mathsf{fma}\left(-0.16666666666666666, ky \cdot ky, 1\right) \cdot ky}}} \]

                                              if 0.00119999999999999989 < ky

                                              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-sin.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky} \cdot \sin ky + {\sin kx}^{2}}} \cdot \sin th \]
                                                7. lift-sin.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \color{blue}{\sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
                                                8. sin-multN/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2}} + {\sin kx}^{2}}} \cdot \sin th \]
                                                9. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
                                                10. unpow2N/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 \]
                                                11. 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 \]
                                                12. 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 \]
                                                13. 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 \]
                                                14. 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 \]
                                                15. 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 \]
                                                16. 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 \]
                                                17. 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 \]
                                              4. Applied rewrites98.9%

                                                \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}}} \cdot \sin th \]
                                              5. Taylor expanded in kx around inf

                                                \[\leadsto \color{blue}{\left(2 \cdot \left(\sin ky \cdot \sqrt{\frac{1}{2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right) + 2 \cdot \left(1 - \cos \left(2 \cdot ky\right)\right)}}\right)\right)} \cdot \sin th \]
                                              6. Step-by-step derivation
                                                1. associate-*r*N/A

                                                  \[\leadsto \color{blue}{\left(\left(2 \cdot \sin ky\right) \cdot \sqrt{\frac{1}{2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right) + 2 \cdot \left(1 - \cos \left(2 \cdot ky\right)\right)}}\right)} \cdot \sin th \]
                                                2. lower-*.f64N/A

                                                  \[\leadsto \color{blue}{\left(\left(2 \cdot \sin ky\right) \cdot \sqrt{\frac{1}{2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right) + 2 \cdot \left(1 - \cos \left(2 \cdot ky\right)\right)}}\right)} \cdot \sin th \]
                                                3. lower-*.f64N/A

                                                  \[\leadsto \left(\color{blue}{\left(2 \cdot \sin ky\right)} \cdot \sqrt{\frac{1}{2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right) + 2 \cdot \left(1 - \cos \left(2 \cdot ky\right)\right)}}\right) \cdot \sin th \]
                                                4. lower-sin.f64N/A

                                                  \[\leadsto \left(\left(2 \cdot \color{blue}{\sin ky}\right) \cdot \sqrt{\frac{1}{2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right) + 2 \cdot \left(1 - \cos \left(2 \cdot ky\right)\right)}}\right) \cdot \sin th \]
                                                5. lower-sqrt.f64N/A

                                                  \[\leadsto \left(\left(2 \cdot \sin ky\right) \cdot \color{blue}{\sqrt{\frac{1}{2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right) + 2 \cdot \left(1 - \cos \left(2 \cdot ky\right)\right)}}}\right) \cdot \sin th \]
                                                6. distribute-lft-outN/A

                                                  \[\leadsto \left(\left(2 \cdot \sin ky\right) \cdot \sqrt{\frac{1}{\color{blue}{2 \cdot \left(\left(1 - \cos \left(2 \cdot kx\right)\right) + \left(1 - \cos \left(2 \cdot ky\right)\right)\right)}}}\right) \cdot \sin th \]
                                                7. associate-/r*N/A

                                                  \[\leadsto \left(\left(2 \cdot \sin ky\right) \cdot \sqrt{\color{blue}{\frac{\frac{1}{2}}{\left(1 - \cos \left(2 \cdot kx\right)\right) + \left(1 - \cos \left(2 \cdot ky\right)\right)}}}\right) \cdot \sin th \]
                                                8. metadata-evalN/A

                                                  \[\leadsto \left(\left(2 \cdot \sin ky\right) \cdot \sqrt{\frac{\color{blue}{\frac{1}{2}}}{\left(1 - \cos \left(2 \cdot kx\right)\right) + \left(1 - \cos \left(2 \cdot ky\right)\right)}}\right) \cdot \sin th \]
                                                9. lower-/.f64N/A

                                                  \[\leadsto \left(\left(2 \cdot \sin ky\right) \cdot \sqrt{\color{blue}{\frac{\frac{1}{2}}{\left(1 - \cos \left(2 \cdot kx\right)\right) + \left(1 - \cos \left(2 \cdot ky\right)\right)}}}\right) \cdot \sin th \]
                                                10. associate-+l-N/A

                                                  \[\leadsto \left(\left(2 \cdot \sin ky\right) \cdot \sqrt{\frac{\frac{1}{2}}{\color{blue}{1 - \left(\cos \left(2 \cdot kx\right) - \left(1 - \cos \left(2 \cdot ky\right)\right)\right)}}}\right) \cdot \sin th \]
                                                11. lower--.f64N/A

                                                  \[\leadsto \left(\left(2 \cdot \sin ky\right) \cdot \sqrt{\frac{\frac{1}{2}}{\color{blue}{1 - \left(\cos \left(2 \cdot kx\right) - \left(1 - \cos \left(2 \cdot ky\right)\right)\right)}}}\right) \cdot \sin th \]
                                                12. lower--.f64N/A

                                                  \[\leadsto \left(\left(2 \cdot \sin ky\right) \cdot \sqrt{\frac{\frac{1}{2}}{1 - \color{blue}{\left(\cos \left(2 \cdot kx\right) - \left(1 - \cos \left(2 \cdot ky\right)\right)\right)}}}\right) \cdot \sin th \]
                                                13. lower-cos.f64N/A

                                                  \[\leadsto \left(\left(2 \cdot \sin ky\right) \cdot \sqrt{\frac{\frac{1}{2}}{1 - \left(\color{blue}{\cos \left(2 \cdot kx\right)} - \left(1 - \cos \left(2 \cdot ky\right)\right)\right)}}\right) \cdot \sin th \]
                                                14. lower-*.f64N/A

                                                  \[\leadsto \left(\left(2 \cdot \sin ky\right) \cdot \sqrt{\frac{\frac{1}{2}}{1 - \left(\cos \color{blue}{\left(2 \cdot kx\right)} - \left(1 - \cos \left(2 \cdot ky\right)\right)\right)}}\right) \cdot \sin th \]
                                              7. Applied rewrites99.0%

                                                \[\leadsto \color{blue}{\left(\left(2 \cdot \sin ky\right) \cdot \sqrt{\frac{0.5}{1 - \left(\cos \left(2 \cdot kx\right) - \left(1 - \cos \left(2 \cdot ky\right)\right)\right)}}\right)} \cdot \sin th \]
                                            3. Recombined 2 regimes into one program.
                                            4. Add Preprocessing

                                            Alternative 31: 74.3% accurate, 1.4× speedup?

                                            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 0.0012:\\ \;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\mathsf{fma}\left(-0.16666666666666666, ky \cdot ky, 1\right) \cdot ky}}\\ \mathbf{else}:\\ \;\;\;\;\left(2 \cdot \left(\sin th \cdot \sin ky\right)\right) \cdot \sqrt{\frac{0.5}{1 - \left(\cos \left(2 \cdot kx\right) - \left(1 - \cos \left(2 \cdot ky\right)\right)\right)}}\\ \end{array} \end{array} \]
                                            (FPCore (kx ky th)
                                             :precision binary64
                                             (if (<= ky 0.0012)
                                               (/
                                                (sin th)
                                                (/
                                                 (hypot (sin ky) (sin kx))
                                                 (* (fma -0.16666666666666666 (* ky ky) 1.0) ky)))
                                               (*
                                                (* 2.0 (* (sin th) (sin ky)))
                                                (sqrt (/ 0.5 (- 1.0 (- (cos (* 2.0 kx)) (- 1.0 (cos (* 2.0 ky))))))))))
                                            double code(double kx, double ky, double th) {
                                            	double tmp;
                                            	if (ky <= 0.0012) {
                                            		tmp = sin(th) / (hypot(sin(ky), sin(kx)) / (fma(-0.16666666666666666, (ky * ky), 1.0) * ky));
                                            	} else {
                                            		tmp = (2.0 * (sin(th) * sin(ky))) * sqrt((0.5 / (1.0 - (cos((2.0 * kx)) - (1.0 - cos((2.0 * ky)))))));
                                            	}
                                            	return tmp;
                                            }
                                            
                                            function code(kx, ky, th)
                                            	tmp = 0.0
                                            	if (ky <= 0.0012)
                                            		tmp = Float64(sin(th) / Float64(hypot(sin(ky), sin(kx)) / Float64(fma(-0.16666666666666666, Float64(ky * ky), 1.0) * ky)));
                                            	else
                                            		tmp = Float64(Float64(2.0 * Float64(sin(th) * sin(ky))) * sqrt(Float64(0.5 / Float64(1.0 - Float64(cos(Float64(2.0 * kx)) - Float64(1.0 - cos(Float64(2.0 * ky))))))));
                                            	end
                                            	return tmp
                                            end
                                            
                                            code[kx_, ky_, th_] := If[LessEqual[ky, 0.0012], N[(N[Sin[th], $MachinePrecision] / N[(N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision] / N[(N[(-0.16666666666666666 * N[(ky * ky), $MachinePrecision] + 1.0), $MachinePrecision] * ky), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * N[(N[Sin[th], $MachinePrecision] * N[Sin[ky], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(0.5 / N[(1.0 - N[(N[Cos[N[(2.0 * kx), $MachinePrecision]], $MachinePrecision] - N[(1.0 - N[Cos[N[(2.0 * ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
                                            
                                            \begin{array}{l}
                                            
                                            \\
                                            \begin{array}{l}
                                            \mathbf{if}\;ky \leq 0.0012:\\
                                            \;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\mathsf{fma}\left(-0.16666666666666666, ky \cdot ky, 1\right) \cdot ky}}\\
                                            
                                            \mathbf{else}:\\
                                            \;\;\;\;\left(2 \cdot \left(\sin th \cdot \sin ky\right)\right) \cdot \sqrt{\frac{0.5}{1 - \left(\cos \left(2 \cdot kx\right) - \left(1 - \cos \left(2 \cdot ky\right)\right)\right)}}\\
                                            
                                            
                                            \end{array}
                                            \end{array}
                                            
                                            Derivation
                                            1. Split input into 2 regimes
                                            2. if ky < 0.00119999999999999989

                                              1. Initial program 90.6%

                                                \[\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. *-commutativeN/A

                                                  \[\leadsto \color{blue}{\sin th \cdot \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                                                3. lift-/.f64N/A

                                                  \[\leadsto \sin th \cdot \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                                                4. clear-numN/A

                                                  \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                5. un-div-invN/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                6. lower-/.f64N/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                7. lower-/.f6490.7

                                                  \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
                                                8. lift-sqrt.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}}{\sin ky}} \]
                                                9. lift-+.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}}{\sin ky}} \]
                                                10. +-commutativeN/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}}{\sin ky}} \]
                                                11. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin ky}^{2}} + {\sin kx}^{2}}}{\sin ky}} \]
                                                12. unpow2N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}}{\sin ky}} \]
                                                13. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\sin ky \cdot \sin ky + \color{blue}{{\sin kx}^{2}}}}{\sin ky}} \]
                                                14. unpow2N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}}{\sin ky}} \]
                                                15. lower-hypot.f6499.8

                                                  \[\leadsto \frac{\sin th}{\frac{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{\sin ky}} \]
                                              4. Applied rewrites99.8%

                                                \[\leadsto \color{blue}{\frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin ky}}} \]
                                              5. Taylor expanded in ky around 0

                                                \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{ky \cdot \left(1 + \frac{-1}{6} \cdot {ky}^{2}\right)}}} \]
                                              6. Step-by-step derivation
                                                1. *-commutativeN/A

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}}} \]
                                                2. lower-*.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}}} \]
                                                3. +-commutativeN/A

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)} \cdot ky}} \]
                                                4. lower-fma.f64N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{\mathsf{fma}\left(\frac{-1}{6}, {ky}^{2}, 1\right)} \cdot ky}} \]
                                                5. unpow2N/A

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\mathsf{fma}\left(\frac{-1}{6}, \color{blue}{ky \cdot ky}, 1\right) \cdot ky}} \]
                                                6. lower-*.f6469.2

                                                  \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\mathsf{fma}\left(-0.16666666666666666, \color{blue}{ky \cdot ky}, 1\right) \cdot ky}} \]
                                              7. Applied rewrites69.2%

                                                \[\leadsto \frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{\mathsf{fma}\left(-0.16666666666666666, ky \cdot ky, 1\right) \cdot ky}}} \]

                                              if 0.00119999999999999989 < ky

                                              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-sin.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky} \cdot \sin ky + {\sin kx}^{2}}} \cdot \sin th \]
                                                7. lift-sin.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \color{blue}{\sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
                                                8. sin-multN/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2}} + {\sin kx}^{2}}} \cdot \sin th \]
                                                9. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
                                                10. unpow2N/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 \]
                                                11. 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 \]
                                                12. 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 \]
                                                13. 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 \]
                                                14. 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 \]
                                                15. 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 \]
                                                16. 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 \]
                                                17. 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 \]
                                              4. Applied rewrites98.9%

                                                \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}}} \cdot \sin th \]
                                              5. Taylor expanded in kx around inf

                                                \[\leadsto \color{blue}{2 \cdot \left(\left(\sin ky \cdot \sin th\right) \cdot \sqrt{\frac{1}{2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right) + 2 \cdot \left(1 - \cos \left(2 \cdot ky\right)\right)}}\right)} \]
                                              6. Step-by-step derivation
                                                1. associate-*r*N/A

                                                  \[\leadsto \color{blue}{\left(2 \cdot \left(\sin ky \cdot \sin th\right)\right) \cdot \sqrt{\frac{1}{2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right) + 2 \cdot \left(1 - \cos \left(2 \cdot ky\right)\right)}}} \]
                                                2. lower-*.f64N/A

                                                  \[\leadsto \color{blue}{\left(2 \cdot \left(\sin ky \cdot \sin th\right)\right) \cdot \sqrt{\frac{1}{2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right) + 2 \cdot \left(1 - \cos \left(2 \cdot ky\right)\right)}}} \]
                                                3. lower-*.f64N/A

                                                  \[\leadsto \color{blue}{\left(2 \cdot \left(\sin ky \cdot \sin th\right)\right)} \cdot \sqrt{\frac{1}{2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right) + 2 \cdot \left(1 - \cos \left(2 \cdot ky\right)\right)}} \]
                                                4. *-commutativeN/A

                                                  \[\leadsto \left(2 \cdot \color{blue}{\left(\sin th \cdot \sin ky\right)}\right) \cdot \sqrt{\frac{1}{2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right) + 2 \cdot \left(1 - \cos \left(2 \cdot ky\right)\right)}} \]
                                                5. lower-*.f64N/A

                                                  \[\leadsto \left(2 \cdot \color{blue}{\left(\sin th \cdot \sin ky\right)}\right) \cdot \sqrt{\frac{1}{2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right) + 2 \cdot \left(1 - \cos \left(2 \cdot ky\right)\right)}} \]
                                                6. lower-sin.f64N/A

                                                  \[\leadsto \left(2 \cdot \left(\color{blue}{\sin th} \cdot \sin ky\right)\right) \cdot \sqrt{\frac{1}{2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right) + 2 \cdot \left(1 - \cos \left(2 \cdot ky\right)\right)}} \]
                                                7. lower-sin.f64N/A

                                                  \[\leadsto \left(2 \cdot \left(\sin th \cdot \color{blue}{\sin ky}\right)\right) \cdot \sqrt{\frac{1}{2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right) + 2 \cdot \left(1 - \cos \left(2 \cdot ky\right)\right)}} \]
                                                8. lower-sqrt.f64N/A

                                                  \[\leadsto \left(2 \cdot \left(\sin th \cdot \sin ky\right)\right) \cdot \color{blue}{\sqrt{\frac{1}{2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right) + 2 \cdot \left(1 - \cos \left(2 \cdot ky\right)\right)}}} \]
                                                9. distribute-lft-outN/A

                                                  \[\leadsto \left(2 \cdot \left(\sin th \cdot \sin ky\right)\right) \cdot \sqrt{\frac{1}{\color{blue}{2 \cdot \left(\left(1 - \cos \left(2 \cdot kx\right)\right) + \left(1 - \cos \left(2 \cdot ky\right)\right)\right)}}} \]
                                                10. associate-/r*N/A

                                                  \[\leadsto \left(2 \cdot \left(\sin th \cdot \sin ky\right)\right) \cdot \sqrt{\color{blue}{\frac{\frac{1}{2}}{\left(1 - \cos \left(2 \cdot kx\right)\right) + \left(1 - \cos \left(2 \cdot ky\right)\right)}}} \]
                                                11. metadata-evalN/A

                                                  \[\leadsto \left(2 \cdot \left(\sin th \cdot \sin ky\right)\right) \cdot \sqrt{\frac{\color{blue}{\frac{1}{2}}}{\left(1 - \cos \left(2 \cdot kx\right)\right) + \left(1 - \cos \left(2 \cdot ky\right)\right)}} \]
                                                12. lower-/.f64N/A

                                                  \[\leadsto \left(2 \cdot \left(\sin th \cdot \sin ky\right)\right) \cdot \sqrt{\color{blue}{\frac{\frac{1}{2}}{\left(1 - \cos \left(2 \cdot kx\right)\right) + \left(1 - \cos \left(2 \cdot ky\right)\right)}}} \]
                                                13. associate-+l-N/A

                                                  \[\leadsto \left(2 \cdot \left(\sin th \cdot \sin ky\right)\right) \cdot \sqrt{\frac{\frac{1}{2}}{\color{blue}{1 - \left(\cos \left(2 \cdot kx\right) - \left(1 - \cos \left(2 \cdot ky\right)\right)\right)}}} \]
                                                14. lower--.f64N/A

                                                  \[\leadsto \left(2 \cdot \left(\sin th \cdot \sin ky\right)\right) \cdot \sqrt{\frac{\frac{1}{2}}{\color{blue}{1 - \left(\cos \left(2 \cdot kx\right) - \left(1 - \cos \left(2 \cdot ky\right)\right)\right)}}} \]
                                              7. Applied rewrites98.9%

                                                \[\leadsto \color{blue}{\left(2 \cdot \left(\sin th \cdot \sin ky\right)\right) \cdot \sqrt{\frac{0.5}{1 - \left(\cos \left(2 \cdot kx\right) - \left(1 - \cos \left(2 \cdot ky\right)\right)\right)}}} \]
                                            3. Recombined 2 regimes into one program.
                                            4. Add Preprocessing

                                            Alternative 32: 10.2% 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 92.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.f6424.9

                                                \[\leadsto \color{blue}{\sin th} \]
                                            5. Applied rewrites24.9%

                                              \[\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.4%

                                                \[\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 rewrites9.8%

                                                  \[\leadsto \left(\left(th \cdot th\right) \cdot -0.16666666666666666\right) \cdot th \]
                                                2. Step-by-step derivation
                                                  1. Applied rewrites9.8%

                                                    \[\leadsto \left(\left(-0.16666666666666666 \cdot th\right) \cdot th\right) \cdot th \]
                                                  2. Add Preprocessing

                                                  Reproduce

                                                  ?
                                                  herbie shell --seed 2024321 
                                                  (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)))