Toniolo and Linder, Equation (3b), real

Percentage Accurate: 93.7% → 99.7%
Time: 11.3s
Alternatives: 19
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 19 alternatives:

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

Initial Program: 93.7% accurate, 1.0× speedup?

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

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

Alternative 1: 99.7% accurate, 1.2× speedup?

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

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

    \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
  2. 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. lower-*.f6495.2

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

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

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

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

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

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

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

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

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

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

Alternative 2: 86.2% accurate, 0.2× speedup?

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

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

\mathbf{elif}\;t\_4 \leq -0.4:\\
\;\;\;\;th \cdot \frac{\sin ky}{t\_2}\\

\mathbf{elif}\;t\_4 \leq 10^{-6}:\\
\;\;\;\;\left(\sqrt{\frac{1}{t\_3}} \cdot \sin ky\right) \cdot \sin th\\

\mathbf{elif}\;t\_4 \leq 0.995:\\
\;\;\;\;\frac{th}{\frac{t\_2}{\sin ky}}\\

\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 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. Initial program 90.3%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. 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. lower-*.f6490.3

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

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

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

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

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

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

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

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

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

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

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

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

      1. Initial program 96.2%

        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      2. 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. lower-*.f6496.2

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

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

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

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

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

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

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

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

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

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

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

        if -0.40000000000000002 < (/.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.99999999999999955e-7

        1. Initial program 99.5%

          \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
        2. 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. lower-*.f6499.5

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          if 9.99999999999999955e-7 < (/.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-pow.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto \frac{\sin th \cdot \sin ky}{\sqrt{\left(\frac{1}{2} + \color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)} \cdot \cos \left(2 \cdot kx\right)\right) + {\sin ky}^{2}}} \]
            11. cancel-sign-sub-invN/A

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

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

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

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

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

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

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

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

            \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin ky}^{2} + {\sin kx}^{2}}} \leq -1:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(kx, \sin ky\right)} \cdot \sin th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin ky}^{2} + {\sin kx}^{2}}} \leq -0.4:\\ \;\;\;\;th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin ky}^{2} + {\sin kx}^{2}}} \leq 10^{-6}:\\ \;\;\;\;\left(\sqrt{\frac{1}{{\sin kx}^{2}}} \cdot \sin ky\right) \cdot \sin th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin ky}^{2} + {\sin kx}^{2}}} \leq 0.995:\\ \;\;\;\;\frac{th}{\frac{\mathsf{hypot}\left(\sin kx, \sin ky\right)}{\sin ky}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(kx, \sin ky\right)} \cdot \sin th\\ \end{array} \]
          11. Add Preprocessing

          Alternative 3: 86.0% accurate, 0.2× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{\sin ky}{\mathsf{hypot}\left(kx, \sin ky\right)} \cdot \sin th\\ t_2 := \frac{\sin ky}{\sqrt{{\sin ky}^{2} + {\sin kx}^{2}}}\\ t_3 := \mathsf{hypot}\left(\sin kx, \sin ky\right)\\ \mathbf{if}\;t\_2 \leq -1:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_2 \leq -0.4:\\ \;\;\;\;th \cdot \frac{\sin ky}{t\_3}\\ \mathbf{elif}\;t\_2 \leq 10^{-6}:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin kx, ky\right)} \cdot \sin th\\ \mathbf{elif}\;t\_2 \leq 0.995:\\ \;\;\;\;\frac{th}{\frac{t\_3}{\sin ky}}\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
          (FPCore (kx ky th)
           :precision binary64
           (let* ((t_1 (* (/ (sin ky) (hypot kx (sin ky))) (sin th)))
                  (t_2 (/ (sin ky) (sqrt (+ (pow (sin ky) 2.0) (pow (sin kx) 2.0)))))
                  (t_3 (hypot (sin kx) (sin ky))))
             (if (<= t_2 -1.0)
               t_1
               (if (<= t_2 -0.4)
                 (* th (/ (sin ky) t_3))
                 (if (<= t_2 1e-6)
                   (* (/ (sin ky) (hypot (sin kx) ky)) (sin th))
                   (if (<= t_2 0.995) (/ th (/ t_3 (sin ky))) t_1))))))
          double code(double kx, double ky, double th) {
          	double t_1 = (sin(ky) / hypot(kx, sin(ky))) * sin(th);
          	double t_2 = sin(ky) / sqrt((pow(sin(ky), 2.0) + pow(sin(kx), 2.0)));
          	double t_3 = hypot(sin(kx), sin(ky));
          	double tmp;
          	if (t_2 <= -1.0) {
          		tmp = t_1;
          	} else if (t_2 <= -0.4) {
          		tmp = th * (sin(ky) / t_3);
          	} else if (t_2 <= 1e-6) {
          		tmp = (sin(ky) / hypot(sin(kx), ky)) * sin(th);
          	} else if (t_2 <= 0.995) {
          		tmp = th / (t_3 / sin(ky));
          	} else {
          		tmp = t_1;
          	}
          	return tmp;
          }
          
          public static double code(double kx, double ky, double th) {
          	double t_1 = (Math.sin(ky) / Math.hypot(kx, Math.sin(ky))) * Math.sin(th);
          	double t_2 = Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(ky), 2.0) + Math.pow(Math.sin(kx), 2.0)));
          	double t_3 = Math.hypot(Math.sin(kx), Math.sin(ky));
          	double tmp;
          	if (t_2 <= -1.0) {
          		tmp = t_1;
          	} else if (t_2 <= -0.4) {
          		tmp = th * (Math.sin(ky) / t_3);
          	} else if (t_2 <= 1e-6) {
          		tmp = (Math.sin(ky) / Math.hypot(Math.sin(kx), ky)) * Math.sin(th);
          	} else if (t_2 <= 0.995) {
          		tmp = th / (t_3 / Math.sin(ky));
          	} else {
          		tmp = t_1;
          	}
          	return tmp;
          }
          
          def code(kx, ky, th):
          	t_1 = (math.sin(ky) / math.hypot(kx, math.sin(ky))) * math.sin(th)
          	t_2 = math.sin(ky) / math.sqrt((math.pow(math.sin(ky), 2.0) + math.pow(math.sin(kx), 2.0)))
          	t_3 = math.hypot(math.sin(kx), math.sin(ky))
          	tmp = 0
          	if t_2 <= -1.0:
          		tmp = t_1
          	elif t_2 <= -0.4:
          		tmp = th * (math.sin(ky) / t_3)
          	elif t_2 <= 1e-6:
          		tmp = (math.sin(ky) / math.hypot(math.sin(kx), ky)) * math.sin(th)
          	elif t_2 <= 0.995:
          		tmp = th / (t_3 / math.sin(ky))
          	else:
          		tmp = t_1
          	return tmp
          
          function code(kx, ky, th)
          	t_1 = Float64(Float64(sin(ky) / hypot(kx, sin(ky))) * sin(th))
          	t_2 = Float64(sin(ky) / sqrt(Float64((sin(ky) ^ 2.0) + (sin(kx) ^ 2.0))))
          	t_3 = hypot(sin(kx), sin(ky))
          	tmp = 0.0
          	if (t_2 <= -1.0)
          		tmp = t_1;
          	elseif (t_2 <= -0.4)
          		tmp = Float64(th * Float64(sin(ky) / t_3));
          	elseif (t_2 <= 1e-6)
          		tmp = Float64(Float64(sin(ky) / hypot(sin(kx), ky)) * sin(th));
          	elseif (t_2 <= 0.995)
          		tmp = Float64(th / Float64(t_3 / sin(ky)));
          	else
          		tmp = t_1;
          	end
          	return tmp
          end
          
          function tmp_2 = code(kx, ky, th)
          	t_1 = (sin(ky) / hypot(kx, sin(ky))) * sin(th);
          	t_2 = sin(ky) / sqrt(((sin(ky) ^ 2.0) + (sin(kx) ^ 2.0)));
          	t_3 = hypot(sin(kx), sin(ky));
          	tmp = 0.0;
          	if (t_2 <= -1.0)
          		tmp = t_1;
          	elseif (t_2 <= -0.4)
          		tmp = th * (sin(ky) / t_3);
          	elseif (t_2 <= 1e-6)
          		tmp = (sin(ky) / hypot(sin(kx), ky)) * sin(th);
          	elseif (t_2 <= 0.995)
          		tmp = th / (t_3 / sin(ky));
          	else
          		tmp = t_1;
          	end
          	tmp_2 = tmp;
          end
          
          code[kx_, ky_, th_] := Block[{t$95$1 = N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[kx ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision]}, If[LessEqual[t$95$2, -1.0], t$95$1, If[LessEqual[t$95$2, -0.4], N[(th * N[(N[Sin[ky], $MachinePrecision] / t$95$3), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 1e-6], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + ky ^ 2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 0.995], N[(th / N[(t$95$3 / N[Sin[ky], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          t_1 := \frac{\sin ky}{\mathsf{hypot}\left(kx, \sin ky\right)} \cdot \sin th\\
          t_2 := \frac{\sin ky}{\sqrt{{\sin ky}^{2} + {\sin kx}^{2}}}\\
          t_3 := \mathsf{hypot}\left(\sin kx, \sin ky\right)\\
          \mathbf{if}\;t\_2 \leq -1:\\
          \;\;\;\;t\_1\\
          
          \mathbf{elif}\;t\_2 \leq -0.4:\\
          \;\;\;\;th \cdot \frac{\sin ky}{t\_3}\\
          
          \mathbf{elif}\;t\_2 \leq 10^{-6}:\\
          \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin kx, ky\right)} \cdot \sin th\\
          
          \mathbf{elif}\;t\_2 \leq 0.995:\\
          \;\;\;\;\frac{th}{\frac{t\_3}{\sin ky}}\\
          
          \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 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. Initial program 90.3%

              \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
            2. 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. lower-*.f6490.3

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

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

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

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

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

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

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

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

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

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

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

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

              1. Initial program 96.2%

                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
              2. 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. lower-*.f6496.2

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

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

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

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

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

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

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

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

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

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

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

                if -0.40000000000000002 < (/.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.99999999999999955e-7

                1. Initial program 99.5%

                  \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                2. 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. lower-*.f6499.5

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

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

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

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

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

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

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

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

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

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

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

                  if 9.99999999999999955e-7 < (/.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-pow.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                      \[\leadsto \frac{\sin th \cdot \sin ky}{\sqrt{\left(\frac{1}{2} + \color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)} \cdot \cos \left(2 \cdot kx\right)\right) + {\sin ky}^{2}}} \]
                    11. cancel-sign-sub-invN/A

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

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

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

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

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

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

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

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

                    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin ky}^{2} + {\sin kx}^{2}}} \leq -1:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(kx, \sin ky\right)} \cdot \sin th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin ky}^{2} + {\sin kx}^{2}}} \leq -0.4:\\ \;\;\;\;th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin ky}^{2} + {\sin kx}^{2}}} \leq 10^{-6}:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin kx, ky\right)} \cdot \sin th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin ky}^{2} + {\sin kx}^{2}}} \leq 0.995:\\ \;\;\;\;\frac{th}{\frac{\mathsf{hypot}\left(\sin kx, \sin ky\right)}{\sin ky}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(kx, \sin ky\right)} \cdot \sin th\\ \end{array} \]
                  11. Add Preprocessing

                  Alternative 4: 86.0% accurate, 0.2× speedup?

                  \[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{\sin ky}{\mathsf{hypot}\left(kx, \sin ky\right)} \cdot \sin th\\ t_2 := \frac{\sin ky}{\sqrt{{\sin ky}^{2} + {\sin kx}^{2}}}\\ t_3 := th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}\\ \mathbf{if}\;t\_2 \leq -1:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_2 \leq -0.4:\\ \;\;\;\;t\_3\\ \mathbf{elif}\;t\_2 \leq 10^{-6}:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin kx, ky\right)} \cdot \sin th\\ \mathbf{elif}\;t\_2 \leq 0.995:\\ \;\;\;\;t\_3\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
                  (FPCore (kx ky th)
                   :precision binary64
                   (let* ((t_1 (* (/ (sin ky) (hypot kx (sin ky))) (sin th)))
                          (t_2 (/ (sin ky) (sqrt (+ (pow (sin ky) 2.0) (pow (sin kx) 2.0)))))
                          (t_3 (* th (/ (sin ky) (hypot (sin kx) (sin ky))))))
                     (if (<= t_2 -1.0)
                       t_1
                       (if (<= t_2 -0.4)
                         t_3
                         (if (<= t_2 1e-6)
                           (* (/ (sin ky) (hypot (sin kx) ky)) (sin th))
                           (if (<= t_2 0.995) t_3 t_1))))))
                  double code(double kx, double ky, double th) {
                  	double t_1 = (sin(ky) / hypot(kx, sin(ky))) * sin(th);
                  	double t_2 = sin(ky) / sqrt((pow(sin(ky), 2.0) + pow(sin(kx), 2.0)));
                  	double t_3 = th * (sin(ky) / hypot(sin(kx), sin(ky)));
                  	double tmp;
                  	if (t_2 <= -1.0) {
                  		tmp = t_1;
                  	} else if (t_2 <= -0.4) {
                  		tmp = t_3;
                  	} else if (t_2 <= 1e-6) {
                  		tmp = (sin(ky) / hypot(sin(kx), ky)) * sin(th);
                  	} else if (t_2 <= 0.995) {
                  		tmp = t_3;
                  	} else {
                  		tmp = t_1;
                  	}
                  	return tmp;
                  }
                  
                  public static double code(double kx, double ky, double th) {
                  	double t_1 = (Math.sin(ky) / Math.hypot(kx, Math.sin(ky))) * Math.sin(th);
                  	double t_2 = Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(ky), 2.0) + Math.pow(Math.sin(kx), 2.0)));
                  	double t_3 = th * (Math.sin(ky) / Math.hypot(Math.sin(kx), Math.sin(ky)));
                  	double tmp;
                  	if (t_2 <= -1.0) {
                  		tmp = t_1;
                  	} else if (t_2 <= -0.4) {
                  		tmp = t_3;
                  	} else if (t_2 <= 1e-6) {
                  		tmp = (Math.sin(ky) / Math.hypot(Math.sin(kx), ky)) * Math.sin(th);
                  	} else if (t_2 <= 0.995) {
                  		tmp = t_3;
                  	} else {
                  		tmp = t_1;
                  	}
                  	return tmp;
                  }
                  
                  def code(kx, ky, th):
                  	t_1 = (math.sin(ky) / math.hypot(kx, math.sin(ky))) * math.sin(th)
                  	t_2 = math.sin(ky) / math.sqrt((math.pow(math.sin(ky), 2.0) + math.pow(math.sin(kx), 2.0)))
                  	t_3 = th * (math.sin(ky) / math.hypot(math.sin(kx), math.sin(ky)))
                  	tmp = 0
                  	if t_2 <= -1.0:
                  		tmp = t_1
                  	elif t_2 <= -0.4:
                  		tmp = t_3
                  	elif t_2 <= 1e-6:
                  		tmp = (math.sin(ky) / math.hypot(math.sin(kx), ky)) * math.sin(th)
                  	elif t_2 <= 0.995:
                  		tmp = t_3
                  	else:
                  		tmp = t_1
                  	return tmp
                  
                  function code(kx, ky, th)
                  	t_1 = Float64(Float64(sin(ky) / hypot(kx, sin(ky))) * sin(th))
                  	t_2 = Float64(sin(ky) / sqrt(Float64((sin(ky) ^ 2.0) + (sin(kx) ^ 2.0))))
                  	t_3 = Float64(th * Float64(sin(ky) / hypot(sin(kx), sin(ky))))
                  	tmp = 0.0
                  	if (t_2 <= -1.0)
                  		tmp = t_1;
                  	elseif (t_2 <= -0.4)
                  		tmp = t_3;
                  	elseif (t_2 <= 1e-6)
                  		tmp = Float64(Float64(sin(ky) / hypot(sin(kx), ky)) * sin(th));
                  	elseif (t_2 <= 0.995)
                  		tmp = t_3;
                  	else
                  		tmp = t_1;
                  	end
                  	return tmp
                  end
                  
                  function tmp_2 = code(kx, ky, th)
                  	t_1 = (sin(ky) / hypot(kx, sin(ky))) * sin(th);
                  	t_2 = sin(ky) / sqrt(((sin(ky) ^ 2.0) + (sin(kx) ^ 2.0)));
                  	t_3 = th * (sin(ky) / hypot(sin(kx), sin(ky)));
                  	tmp = 0.0;
                  	if (t_2 <= -1.0)
                  		tmp = t_1;
                  	elseif (t_2 <= -0.4)
                  		tmp = t_3;
                  	elseif (t_2 <= 1e-6)
                  		tmp = (sin(ky) / hypot(sin(kx), ky)) * sin(th);
                  	elseif (t_2 <= 0.995)
                  		tmp = t_3;
                  	else
                  		tmp = t_1;
                  	end
                  	tmp_2 = tmp;
                  end
                  
                  code[kx_, ky_, th_] := Block[{t$95$1 = N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[kx ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(th * N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -1.0], t$95$1, If[LessEqual[t$95$2, -0.4], t$95$3, If[LessEqual[t$95$2, 1e-6], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + ky ^ 2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 0.995], t$95$3, t$95$1]]]]]]]
                  
                  \begin{array}{l}
                  
                  \\
                  \begin{array}{l}
                  t_1 := \frac{\sin ky}{\mathsf{hypot}\left(kx, \sin ky\right)} \cdot \sin th\\
                  t_2 := \frac{\sin ky}{\sqrt{{\sin ky}^{2} + {\sin kx}^{2}}}\\
                  t_3 := th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}\\
                  \mathbf{if}\;t\_2 \leq -1:\\
                  \;\;\;\;t\_1\\
                  
                  \mathbf{elif}\;t\_2 \leq -0.4:\\
                  \;\;\;\;t\_3\\
                  
                  \mathbf{elif}\;t\_2 \leq 10^{-6}:\\
                  \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin kx, ky\right)} \cdot \sin th\\
                  
                  \mathbf{elif}\;t\_2 \leq 0.995:\\
                  \;\;\;\;t\_3\\
                  
                  \mathbf{else}:\\
                  \;\;\;\;t\_1\\
                  
                  
                  \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. Initial program 90.3%

                      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                    2. 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. lower-*.f6490.3

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

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

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

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

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

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

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

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

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

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

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

                      if -1 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.40000000000000002 or 9.99999999999999955e-7 < (/.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 98.0%

                        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                      2. 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. lower-*.f6498.0

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

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

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

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

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

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

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

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

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

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

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

                        if -0.40000000000000002 < (/.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.99999999999999955e-7

                        1. Initial program 99.5%

                          \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                        2. 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. lower-*.f6499.5

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

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

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

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

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

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

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

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

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

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

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

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

                        Alternative 5: 86.0% accurate, 0.2× speedup?

                        \[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{\sin ky}{\mathsf{hypot}\left(kx, \sin ky\right)} \cdot \sin th\\ t_2 := \frac{\sin ky}{\sqrt{{\sin ky}^{2} + {\sin kx}^{2}}}\\ t_3 := th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}\\ \mathbf{if}\;t\_2 \leq -1:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_2 \leq -0.4:\\ \;\;\;\;t\_3\\ \mathbf{elif}\;t\_2 \leq 10^{-6}:\\ \;\;\;\;\frac{ky}{\mathsf{hypot}\left(\sin kx, ky\right)} \cdot \sin th\\ \mathbf{elif}\;t\_2 \leq 0.995:\\ \;\;\;\;t\_3\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
                        (FPCore (kx ky th)
                         :precision binary64
                         (let* ((t_1 (* (/ (sin ky) (hypot kx (sin ky))) (sin th)))
                                (t_2 (/ (sin ky) (sqrt (+ (pow (sin ky) 2.0) (pow (sin kx) 2.0)))))
                                (t_3 (* th (/ (sin ky) (hypot (sin kx) (sin ky))))))
                           (if (<= t_2 -1.0)
                             t_1
                             (if (<= t_2 -0.4)
                               t_3
                               (if (<= t_2 1e-6)
                                 (* (/ ky (hypot (sin kx) ky)) (sin th))
                                 (if (<= t_2 0.995) t_3 t_1))))))
                        double code(double kx, double ky, double th) {
                        	double t_1 = (sin(ky) / hypot(kx, sin(ky))) * sin(th);
                        	double t_2 = sin(ky) / sqrt((pow(sin(ky), 2.0) + pow(sin(kx), 2.0)));
                        	double t_3 = th * (sin(ky) / hypot(sin(kx), sin(ky)));
                        	double tmp;
                        	if (t_2 <= -1.0) {
                        		tmp = t_1;
                        	} else if (t_2 <= -0.4) {
                        		tmp = t_3;
                        	} else if (t_2 <= 1e-6) {
                        		tmp = (ky / hypot(sin(kx), ky)) * sin(th);
                        	} else if (t_2 <= 0.995) {
                        		tmp = t_3;
                        	} else {
                        		tmp = t_1;
                        	}
                        	return tmp;
                        }
                        
                        public static double code(double kx, double ky, double th) {
                        	double t_1 = (Math.sin(ky) / Math.hypot(kx, Math.sin(ky))) * Math.sin(th);
                        	double t_2 = Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(ky), 2.0) + Math.pow(Math.sin(kx), 2.0)));
                        	double t_3 = th * (Math.sin(ky) / Math.hypot(Math.sin(kx), Math.sin(ky)));
                        	double tmp;
                        	if (t_2 <= -1.0) {
                        		tmp = t_1;
                        	} else if (t_2 <= -0.4) {
                        		tmp = t_3;
                        	} else if (t_2 <= 1e-6) {
                        		tmp = (ky / Math.hypot(Math.sin(kx), ky)) * Math.sin(th);
                        	} else if (t_2 <= 0.995) {
                        		tmp = t_3;
                        	} else {
                        		tmp = t_1;
                        	}
                        	return tmp;
                        }
                        
                        def code(kx, ky, th):
                        	t_1 = (math.sin(ky) / math.hypot(kx, math.sin(ky))) * math.sin(th)
                        	t_2 = math.sin(ky) / math.sqrt((math.pow(math.sin(ky), 2.0) + math.pow(math.sin(kx), 2.0)))
                        	t_3 = th * (math.sin(ky) / math.hypot(math.sin(kx), math.sin(ky)))
                        	tmp = 0
                        	if t_2 <= -1.0:
                        		tmp = t_1
                        	elif t_2 <= -0.4:
                        		tmp = t_3
                        	elif t_2 <= 1e-6:
                        		tmp = (ky / math.hypot(math.sin(kx), ky)) * math.sin(th)
                        	elif t_2 <= 0.995:
                        		tmp = t_3
                        	else:
                        		tmp = t_1
                        	return tmp
                        
                        function code(kx, ky, th)
                        	t_1 = Float64(Float64(sin(ky) / hypot(kx, sin(ky))) * sin(th))
                        	t_2 = Float64(sin(ky) / sqrt(Float64((sin(ky) ^ 2.0) + (sin(kx) ^ 2.0))))
                        	t_3 = Float64(th * Float64(sin(ky) / hypot(sin(kx), sin(ky))))
                        	tmp = 0.0
                        	if (t_2 <= -1.0)
                        		tmp = t_1;
                        	elseif (t_2 <= -0.4)
                        		tmp = t_3;
                        	elseif (t_2 <= 1e-6)
                        		tmp = Float64(Float64(ky / hypot(sin(kx), ky)) * sin(th));
                        	elseif (t_2 <= 0.995)
                        		tmp = t_3;
                        	else
                        		tmp = t_1;
                        	end
                        	return tmp
                        end
                        
                        function tmp_2 = code(kx, ky, th)
                        	t_1 = (sin(ky) / hypot(kx, sin(ky))) * sin(th);
                        	t_2 = sin(ky) / sqrt(((sin(ky) ^ 2.0) + (sin(kx) ^ 2.0)));
                        	t_3 = th * (sin(ky) / hypot(sin(kx), sin(ky)));
                        	tmp = 0.0;
                        	if (t_2 <= -1.0)
                        		tmp = t_1;
                        	elseif (t_2 <= -0.4)
                        		tmp = t_3;
                        	elseif (t_2 <= 1e-6)
                        		tmp = (ky / hypot(sin(kx), ky)) * sin(th);
                        	elseif (t_2 <= 0.995)
                        		tmp = t_3;
                        	else
                        		tmp = t_1;
                        	end
                        	tmp_2 = tmp;
                        end
                        
                        code[kx_, ky_, th_] := Block[{t$95$1 = N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[kx ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(th * N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -1.0], t$95$1, If[LessEqual[t$95$2, -0.4], t$95$3, If[LessEqual[t$95$2, 1e-6], N[(N[(ky / N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + ky ^ 2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 0.995], t$95$3, t$95$1]]]]]]]
                        
                        \begin{array}{l}
                        
                        \\
                        \begin{array}{l}
                        t_1 := \frac{\sin ky}{\mathsf{hypot}\left(kx, \sin ky\right)} \cdot \sin th\\
                        t_2 := \frac{\sin ky}{\sqrt{{\sin ky}^{2} + {\sin kx}^{2}}}\\
                        t_3 := th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}\\
                        \mathbf{if}\;t\_2 \leq -1:\\
                        \;\;\;\;t\_1\\
                        
                        \mathbf{elif}\;t\_2 \leq -0.4:\\
                        \;\;\;\;t\_3\\
                        
                        \mathbf{elif}\;t\_2 \leq 10^{-6}:\\
                        \;\;\;\;\frac{ky}{\mathsf{hypot}\left(\sin kx, ky\right)} \cdot \sin th\\
                        
                        \mathbf{elif}\;t\_2 \leq 0.995:\\
                        \;\;\;\;t\_3\\
                        
                        \mathbf{else}:\\
                        \;\;\;\;t\_1\\
                        
                        
                        \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. Initial program 90.3%

                            \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                          2. 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. lower-*.f6490.3

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

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

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

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

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

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

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

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

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

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

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

                            if -1 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.40000000000000002 or 9.99999999999999955e-7 < (/.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 98.0%

                              \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                            2. 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. lower-*.f6498.0

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

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

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

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

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

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

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

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

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

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

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

                              if -0.40000000000000002 < (/.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.99999999999999955e-7

                              1. Initial program 99.5%

                                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                              2. 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. lower-*.f6499.5

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

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

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

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

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

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

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

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

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

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

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

                                  \[\leadsto \sin th \cdot \frac{\color{blue}{ky}}{\mathsf{hypot}\left(\sin kx, ky\right)} \]
                                3. Step-by-step derivation
                                  1. Applied rewrites95.9%

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

                                  \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin ky}^{2} + {\sin kx}^{2}}} \leq -1:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(kx, \sin ky\right)} \cdot \sin th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin ky}^{2} + {\sin kx}^{2}}} \leq -0.4:\\ \;\;\;\;th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin ky}^{2} + {\sin kx}^{2}}} \leq 10^{-6}:\\ \;\;\;\;\frac{ky}{\mathsf{hypot}\left(\sin kx, ky\right)} \cdot \sin th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin ky}^{2} + {\sin kx}^{2}}} \leq 0.995:\\ \;\;\;\;th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(kx, \sin ky\right)} \cdot \sin th\\ \end{array} \]
                                6. Add Preprocessing

                                Alternative 6: 59.6% accurate, 0.7× speedup?

                                \[\begin{array}{l} \\ \begin{array}{l} t_1 := {\sin ky}^{2}\\ \mathbf{if}\;\frac{\sin ky}{\sqrt{t\_1 + {\sin kx}^{2}}} \leq -0.4:\\ \;\;\;\;\sqrt{\frac{1}{t\_1}} \cdot \left(\sin ky \cdot th\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{ky}{\mathsf{hypot}\left(\sin kx, ky\right)} \cdot \sin th\\ \end{array} \end{array} \]
                                (FPCore (kx ky th)
                                 :precision binary64
                                 (let* ((t_1 (pow (sin ky) 2.0)))
                                   (if (<= (/ (sin ky) (sqrt (+ t_1 (pow (sin kx) 2.0)))) -0.4)
                                     (* (sqrt (/ 1.0 t_1)) (* (sin ky) th))
                                     (* (/ ky (hypot (sin kx) ky)) (sin th)))))
                                double code(double kx, double ky, double th) {
                                	double t_1 = pow(sin(ky), 2.0);
                                	double tmp;
                                	if ((sin(ky) / sqrt((t_1 + pow(sin(kx), 2.0)))) <= -0.4) {
                                		tmp = sqrt((1.0 / t_1)) * (sin(ky) * th);
                                	} else {
                                		tmp = (ky / hypot(sin(kx), ky)) * sin(th);
                                	}
                                	return tmp;
                                }
                                
                                public static double code(double kx, double ky, double th) {
                                	double t_1 = Math.pow(Math.sin(ky), 2.0);
                                	double tmp;
                                	if ((Math.sin(ky) / Math.sqrt((t_1 + Math.pow(Math.sin(kx), 2.0)))) <= -0.4) {
                                		tmp = Math.sqrt((1.0 / t_1)) * (Math.sin(ky) * th);
                                	} else {
                                		tmp = (ky / Math.hypot(Math.sin(kx), ky)) * Math.sin(th);
                                	}
                                	return tmp;
                                }
                                
                                def code(kx, ky, th):
                                	t_1 = math.pow(math.sin(ky), 2.0)
                                	tmp = 0
                                	if (math.sin(ky) / math.sqrt((t_1 + math.pow(math.sin(kx), 2.0)))) <= -0.4:
                                		tmp = math.sqrt((1.0 / t_1)) * (math.sin(ky) * th)
                                	else:
                                		tmp = (ky / math.hypot(math.sin(kx), ky)) * math.sin(th)
                                	return tmp
                                
                                function code(kx, ky, th)
                                	t_1 = sin(ky) ^ 2.0
                                	tmp = 0.0
                                	if (Float64(sin(ky) / sqrt(Float64(t_1 + (sin(kx) ^ 2.0)))) <= -0.4)
                                		tmp = Float64(sqrt(Float64(1.0 / t_1)) * Float64(sin(ky) * th));
                                	else
                                		tmp = Float64(Float64(ky / hypot(sin(kx), ky)) * sin(th));
                                	end
                                	return tmp
                                end
                                
                                function tmp_2 = code(kx, ky, th)
                                	t_1 = sin(ky) ^ 2.0;
                                	tmp = 0.0;
                                	if ((sin(ky) / sqrt((t_1 + (sin(kx) ^ 2.0)))) <= -0.4)
                                		tmp = sqrt((1.0 / t_1)) * (sin(ky) * th);
                                	else
                                		tmp = (ky / hypot(sin(kx), ky)) * sin(th);
                                	end
                                	tmp_2 = tmp;
                                end
                                
                                code[kx_, ky_, th_] := Block[{t$95$1 = N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]}, If[LessEqual[N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(t$95$1 + N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -0.4], N[(N[Sqrt[N[(1.0 / t$95$1), $MachinePrecision]], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] * th), $MachinePrecision]), $MachinePrecision], N[(N[(ky / N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + ky ^ 2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]]]
                                
                                \begin{array}{l}
                                
                                \\
                                \begin{array}{l}
                                t_1 := {\sin ky}^{2}\\
                                \mathbf{if}\;\frac{\sin ky}{\sqrt{t\_1 + {\sin kx}^{2}}} \leq -0.4:\\
                                \;\;\;\;\sqrt{\frac{1}{t\_1}} \cdot \left(\sin ky \cdot th\right)\\
                                
                                \mathbf{else}:\\
                                \;\;\;\;\frac{ky}{\mathsf{hypot}\left(\sin kx, ky\right)} \cdot \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.40000000000000002

                                  1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                    \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{{\sin ky}^{2}}} \]
                                  7. Step-by-step derivation
                                    1. Applied rewrites29.7%

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

                                    if -0.40000000000000002 < (/.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 95.9%

                                      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                    2. 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. lower-*.f6495.9

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

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

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

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

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

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

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

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

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

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

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

                                        \[\leadsto \sin th \cdot \frac{\color{blue}{ky}}{\mathsf{hypot}\left(\sin kx, ky\right)} \]
                                      3. Step-by-step derivation
                                        1. Applied rewrites76.0%

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

                                        \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin ky}^{2} + {\sin kx}^{2}}} \leq -0.4:\\ \;\;\;\;\sqrt{\frac{1}{{\sin ky}^{2}}} \cdot \left(\sin ky \cdot th\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{ky}{\mathsf{hypot}\left(\sin kx, ky\right)} \cdot \sin th\\ \end{array} \]
                                      6. Add Preprocessing

                                      Alternative 7: 44.2% accurate, 0.8× speedup?

                                      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin ky}^{2} + {\sin kx}^{2}}} \leq 10^{-6}:\\ \;\;\;\;\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 ky) 2.0) (pow (sin kx) 2.0)))) 1e-6)
                                         (/ (sin th) (/ (sin kx) ky))
                                         (sin th)))
                                      double code(double kx, double ky, double th) {
                                      	double tmp;
                                      	if ((sin(ky) / sqrt((pow(sin(ky), 2.0) + pow(sin(kx), 2.0)))) <= 1e-6) {
                                      		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(ky) ** 2.0d0) + (sin(kx) ** 2.0d0)))) <= 1d-6) 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(ky), 2.0) + Math.pow(Math.sin(kx), 2.0)))) <= 1e-6) {
                                      		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(ky), 2.0) + math.pow(math.sin(kx), 2.0)))) <= 1e-6:
                                      		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(ky) ^ 2.0) + (sin(kx) ^ 2.0)))) <= 1e-6)
                                      		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(ky) ^ 2.0) + (sin(kx) ^ 2.0)))) <= 1e-6)
                                      		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[ky], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 1e-6], 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 ky}^{2} + {\sin kx}^{2}}} \leq 10^{-6}:\\
                                      \;\;\;\;\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))))) < 9.99999999999999955e-7

                                        1. Initial program 97.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                            \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(\cos \color{blue}{\left(2 \cdot kx\right)}, \mathsf{neg}\left(\frac{1}{2}\right), \frac{1}{2}\right) + {\sin ky}^{2}}} \cdot \sin th \]
                                          15. metadata-eval83.0

                                            \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(\cos \left(2 \cdot kx\right), \color{blue}{-0.5}, 0.5\right) + {\sin ky}^{2}}} \cdot \sin th \]
                                        4. Applied rewrites83.0%

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

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

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

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

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

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

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

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

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

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

                                            \[\leadsto \frac{\sin th \cdot \sin ky}{\sqrt{\left(\frac{1}{2} + \color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)} \cdot \cos \left(2 \cdot kx\right)\right) + {\sin ky}^{2}}} \]
                                          11. cancel-sign-sub-invN/A

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

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

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

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

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

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

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

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

                                            \[\leadsto \frac{\sin th}{\frac{\color{blue}{\sin kx}}{ky}} \]
                                        9. Applied rewrites35.4%

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

                                        if 9.99999999999999955e-7 < (/.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.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.f6470.1

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

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

                                        \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin ky}^{2} + {\sin kx}^{2}}} \leq 10^{-6}:\\ \;\;\;\;\frac{\sin th}{\frac{\sin kx}{ky}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
                                      5. Add Preprocessing

                                      Alternative 8: 44.2% accurate, 0.8× speedup?

                                      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin ky}^{2} + {\sin kx}^{2}}} \leq 10^{-6}:\\ \;\;\;\;\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 ky) 2.0) (pow (sin kx) 2.0)))) 1e-6)
                                         (* (/ ky (sin kx)) (sin th))
                                         (sin th)))
                                      double code(double kx, double ky, double th) {
                                      	double tmp;
                                      	if ((sin(ky) / sqrt((pow(sin(ky), 2.0) + pow(sin(kx), 2.0)))) <= 1e-6) {
                                      		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(ky) ** 2.0d0) + (sin(kx) ** 2.0d0)))) <= 1d-6) 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(ky), 2.0) + Math.pow(Math.sin(kx), 2.0)))) <= 1e-6) {
                                      		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(ky), 2.0) + math.pow(math.sin(kx), 2.0)))) <= 1e-6:
                                      		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(ky) ^ 2.0) + (sin(kx) ^ 2.0)))) <= 1e-6)
                                      		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(ky) ^ 2.0) + (sin(kx) ^ 2.0)))) <= 1e-6)
                                      		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[ky], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 1e-6], 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 ky}^{2} + {\sin kx}^{2}}} \leq 10^{-6}:\\
                                      \;\;\;\;\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))))) < 9.99999999999999955e-7

                                        1. Initial program 97.0%

                                          \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                        2. 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. lower-*.f6497.0

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

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

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

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

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

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

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

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

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

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

                                            \[\leadsto \sin th \cdot \color{blue}{\frac{ky}{\sin kx}} \]
                                          2. lower-sin.f6435.4

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

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

                                        if 9.99999999999999955e-7 < (/.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.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.f6470.1

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

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

                                        \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin ky}^{2} + {\sin kx}^{2}}} \leq 10^{-6}:\\ \;\;\;\;\frac{ky}{\sin kx} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
                                      5. Add Preprocessing

                                      Alternative 9: 36.4% accurate, 0.8× speedup?

                                      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin ky}^{2} + {\sin kx}^{2}}} \leq 5 \cdot 10^{-15}:\\ \;\;\;\;\frac{\sin ky}{\sin kx} \cdot th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
                                      (FPCore (kx ky th)
                                       :precision binary64
                                       (if (<= (/ (sin ky) (sqrt (+ (pow (sin ky) 2.0) (pow (sin kx) 2.0)))) 5e-15)
                                         (* (/ (sin ky) (sin kx)) th)
                                         (sin th)))
                                      double code(double kx, double ky, double th) {
                                      	double tmp;
                                      	if ((sin(ky) / sqrt((pow(sin(ky), 2.0) + pow(sin(kx), 2.0)))) <= 5e-15) {
                                      		tmp = (sin(ky) / sin(kx)) * 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(ky) ** 2.0d0) + (sin(kx) ** 2.0d0)))) <= 5d-15) then
                                              tmp = (sin(ky) / sin(kx)) * 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(ky), 2.0) + Math.pow(Math.sin(kx), 2.0)))) <= 5e-15) {
                                      		tmp = (Math.sin(ky) / Math.sin(kx)) * 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(ky), 2.0) + math.pow(math.sin(kx), 2.0)))) <= 5e-15:
                                      		tmp = (math.sin(ky) / math.sin(kx)) * th
                                      	else:
                                      		tmp = math.sin(th)
                                      	return tmp
                                      
                                      function code(kx, ky, th)
                                      	tmp = 0.0
                                      	if (Float64(sin(ky) / sqrt(Float64((sin(ky) ^ 2.0) + (sin(kx) ^ 2.0)))) <= 5e-15)
                                      		tmp = Float64(Float64(sin(ky) / sin(kx)) * th);
                                      	else
                                      		tmp = sin(th);
                                      	end
                                      	return tmp
                                      end
                                      
                                      function tmp_2 = code(kx, ky, th)
                                      	tmp = 0.0;
                                      	if ((sin(ky) / sqrt(((sin(ky) ^ 2.0) + (sin(kx) ^ 2.0)))) <= 5e-15)
                                      		tmp = (sin(ky) / sin(kx)) * 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[ky], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 5e-15], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision] * th), $MachinePrecision], N[Sin[th], $MachinePrecision]]
                                      
                                      \begin{array}{l}
                                      
                                      \\
                                      \begin{array}{l}
                                      \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin ky}^{2} + {\sin kx}^{2}}} \leq 5 \cdot 10^{-15}:\\
                                      \;\;\;\;\frac{\sin ky}{\sin kx} \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))))) < 4.99999999999999999e-15

                                        1. Initial program 97.0%

                                          \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                        2. 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. lower-*.f6497.0

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

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

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

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

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

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

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

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

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

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

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

                                            \[\leadsto th \cdot \frac{\sin ky}{\color{blue}{\sin kx}} \]
                                          3. Step-by-step derivation
                                            1. lower-sin.f6423.0

                                              \[\leadsto th \cdot \frac{\sin ky}{\color{blue}{\sin kx}} \]
                                          4. Applied rewrites23.0%

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

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

                                          1. Initial program 91.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.f6468.0

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

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

                                          \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin ky}^{2} + {\sin kx}^{2}}} \leq 5 \cdot 10^{-15}:\\ \;\;\;\;\frac{\sin ky}{\sin kx} \cdot th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
                                        9. Add Preprocessing

                                        Alternative 10: 99.4% accurate, 1.0× speedup?

                                        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;{\sin kx}^{2} \leq 4 \cdot 10^{-12}:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(kx, \sin ky\right)} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky}{\sqrt{\left(0.5 - \cos \left(2 \cdot ky\right) \cdot 0.5\right) + \mathsf{fma}\left(\cos \left(2 \cdot kx\right), -0.5, 0.5\right)}} \cdot \sin th\\ \end{array} \end{array} \]
                                        (FPCore (kx ky th)
                                         :precision binary64
                                         (if (<= (pow (sin kx) 2.0) 4e-12)
                                           (* (/ (sin ky) (hypot kx (sin ky))) (sin th))
                                           (*
                                            (/
                                             (sin ky)
                                             (sqrt
                                              (+ (- 0.5 (* (cos (* 2.0 ky)) 0.5)) (fma (cos (* 2.0 kx)) -0.5 0.5))))
                                            (sin th))))
                                        double code(double kx, double ky, double th) {
                                        	double tmp;
                                        	if (pow(sin(kx), 2.0) <= 4e-12) {
                                        		tmp = (sin(ky) / hypot(kx, sin(ky))) * sin(th);
                                        	} else {
                                        		tmp = (sin(ky) / sqrt(((0.5 - (cos((2.0 * ky)) * 0.5)) + fma(cos((2.0 * kx)), -0.5, 0.5)))) * sin(th);
                                        	}
                                        	return tmp;
                                        }
                                        
                                        function code(kx, ky, th)
                                        	tmp = 0.0
                                        	if ((sin(kx) ^ 2.0) <= 4e-12)
                                        		tmp = Float64(Float64(sin(ky) / hypot(kx, sin(ky))) * sin(th));
                                        	else
                                        		tmp = Float64(Float64(sin(ky) / sqrt(Float64(Float64(0.5 - Float64(cos(Float64(2.0 * ky)) * 0.5)) + fma(cos(Float64(2.0 * kx)), -0.5, 0.5)))) * sin(th));
                                        	end
                                        	return tmp
                                        end
                                        
                                        code[kx_, ky_, th_] := If[LessEqual[N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision], 4e-12], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[kx ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(0.5 - N[(N[Cos[N[(2.0 * ky), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision] + N[(N[Cos[N[(2.0 * kx), $MachinePrecision]], $MachinePrecision] * -0.5 + 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]]
                                        
                                        \begin{array}{l}
                                        
                                        \\
                                        \begin{array}{l}
                                        \mathbf{if}\;{\sin kx}^{2} \leq 4 \cdot 10^{-12}:\\
                                        \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(kx, \sin ky\right)} \cdot \sin th\\
                                        
                                        \mathbf{else}:\\
                                        \;\;\;\;\frac{\sin ky}{\sqrt{\left(0.5 - \cos \left(2 \cdot ky\right) \cdot 0.5\right) + \mathsf{fma}\left(\cos \left(2 \cdot kx\right), -0.5, 0.5\right)}} \cdot \sin th\\
                                        
                                        
                                        \end{array}
                                        \end{array}
                                        
                                        Derivation
                                        1. Split input into 2 regimes
                                        2. if (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) < 3.99999999999999992e-12

                                          1. Initial program 91.6%

                                            \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                          2. 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. lower-*.f6491.6

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

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

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

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

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

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

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

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

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

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

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

                                            if 3.99999999999999992e-12 < (pow.f64 (sin.f64 kx) #s(literal 2 binary64))

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(\cos \color{blue}{\left(2 \cdot kx\right)}, \mathsf{neg}\left(\frac{1}{2}\right), \frac{1}{2}\right) + {\sin ky}^{2}}} \cdot \sin th \]
                                              15. metadata-eval98.4

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                          Alternative 11: 35.7% accurate, 1.0× speedup?

                                          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin ky}^{2} + {\sin kx}^{2}}} \leq 5 \cdot 10^{-15}:\\ \;\;\;\;\frac{th}{\sin kx} \cdot ky\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
                                          (FPCore (kx ky th)
                                           :precision binary64
                                           (if (<= (/ (sin ky) (sqrt (+ (pow (sin ky) 2.0) (pow (sin kx) 2.0)))) 5e-15)
                                             (* (/ th (sin kx)) ky)
                                             (sin th)))
                                          double code(double kx, double ky, double th) {
                                          	double tmp;
                                          	if ((sin(ky) / sqrt((pow(sin(ky), 2.0) + pow(sin(kx), 2.0)))) <= 5e-15) {
                                          		tmp = (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(ky) ** 2.0d0) + (sin(kx) ** 2.0d0)))) <= 5d-15) then
                                                  tmp = (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(ky), 2.0) + Math.pow(Math.sin(kx), 2.0)))) <= 5e-15) {
                                          		tmp = (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(ky), 2.0) + math.pow(math.sin(kx), 2.0)))) <= 5e-15:
                                          		tmp = (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(ky) ^ 2.0) + (sin(kx) ^ 2.0)))) <= 5e-15)
                                          		tmp = Float64(Float64(th / 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(ky) ^ 2.0) + (sin(kx) ^ 2.0)))) <= 5e-15)
                                          		tmp = (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[ky], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 5e-15], N[(N[(th / N[Sin[kx], $MachinePrecision]), $MachinePrecision] * ky), $MachinePrecision], N[Sin[th], $MachinePrecision]]
                                          
                                          \begin{array}{l}
                                          
                                          \\
                                          \begin{array}{l}
                                          \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin ky}^{2} + {\sin kx}^{2}}} \leq 5 \cdot 10^{-15}:\\
                                          \;\;\;\;\frac{th}{\sin kx} \cdot 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))))) < 4.99999999999999999e-15

                                            1. Initial program 97.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                              \[\leadsto \frac{ky \cdot th}{\color{blue}{\sin kx}} \]
                                            7. Step-by-step derivation
                                              1. Applied rewrites22.2%

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

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

                                              1. Initial program 91.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.f6468.0

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

                                                \[\leadsto \color{blue}{\sin th} \]
                                            8. Recombined 2 regimes into one program.
                                            9. Final simplification37.2%

                                              \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin ky}^{2} + {\sin kx}^{2}}} \leq 5 \cdot 10^{-15}:\\ \;\;\;\;\frac{th}{\sin kx} \cdot ky\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
                                            10. Add Preprocessing

                                            Alternative 12: 48.2% accurate, 1.2× speedup?

                                            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.01:\\ \;\;\;\;\left(\sqrt{\frac{1}{\mathsf{fma}\left(\cos \left(2 \cdot kx\right), -0.5, 0.5\right)}} \cdot ky\right) \cdot \sin th\\ \mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-96}:\\ \;\;\;\;\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.01)
                                               (* (* (sqrt (/ 1.0 (fma (cos (* 2.0 kx)) -0.5 0.5))) ky) (sin th))
                                               (if (<= (sin kx) 5e-96) (sin th) (* (/ (sin ky) (sin kx)) (sin th)))))
                                            double code(double kx, double ky, double th) {
                                            	double tmp;
                                            	if (sin(kx) <= -0.01) {
                                            		tmp = (sqrt((1.0 / fma(cos((2.0 * kx)), -0.5, 0.5))) * ky) * sin(th);
                                            	} else if (sin(kx) <= 5e-96) {
                                            		tmp = sin(th);
                                            	} else {
                                            		tmp = (sin(ky) / sin(kx)) * sin(th);
                                            	}
                                            	return tmp;
                                            }
                                            
                                            function code(kx, ky, th)
                                            	tmp = 0.0
                                            	if (sin(kx) <= -0.01)
                                            		tmp = Float64(Float64(sqrt(Float64(1.0 / fma(cos(Float64(2.0 * kx)), -0.5, 0.5))) * ky) * sin(th));
                                            	elseif (sin(kx) <= 5e-96)
                                            		tmp = sin(th);
                                            	else
                                            		tmp = Float64(Float64(sin(ky) / sin(kx)) * sin(th));
                                            	end
                                            	return tmp
                                            end
                                            
                                            code[kx_, ky_, th_] := If[LessEqual[N[Sin[kx], $MachinePrecision], -0.01], N[(N[(N[Sqrt[N[(1.0 / N[(N[Cos[N[(2.0 * kx), $MachinePrecision]], $MachinePrecision] * -0.5 + 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * ky), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[kx], $MachinePrecision], 5e-96], 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.01:\\
                                            \;\;\;\;\left(\sqrt{\frac{1}{\mathsf{fma}\left(\cos \left(2 \cdot kx\right), -0.5, 0.5\right)}} \cdot ky\right) \cdot \sin th\\
                                            
                                            \mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-96}:\\
                                            \;\;\;\;\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.0100000000000000002

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(\cos \color{blue}{\left(2 \cdot kx\right)}, \mathsf{neg}\left(\frac{1}{2}\right), \frac{1}{2}\right) + {\sin ky}^{2}}} \cdot \sin th \]
                                                15. metadata-eval99.3

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(\cos \left(2 \cdot kx\right), \color{blue}{-0.5}, 0.5\right) + {\sin ky}^{2}}} \cdot \sin th \]
                                              4. Applied rewrites99.3%

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

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

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

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

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

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

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

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

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

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

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

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

                                              if -0.0100000000000000002 < (sin.f64 kx) < 4.99999999999999995e-96

                                              1. Initial program 90.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.f6440.4

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

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

                                              if 4.99999999999999995e-96 < (sin.f64 kx)

                                              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}{\color{blue}{\sin kx}} \cdot \sin th \]
                                              4. Step-by-step derivation
                                                1. lower-sin.f6459.4

                                                  \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
                                              5. Applied rewrites59.4%

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

                                            Alternative 13: 99.6% accurate, 1.2× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(\cos \color{blue}{\left(2 \cdot kx\right)}, \mathsf{neg}\left(\frac{1}{2}\right), \frac{1}{2}\right) + {\sin ky}^{2}}} \cdot \sin th \]
                                              15. metadata-eval85.6

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

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

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

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

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

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

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

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

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

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

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

                                                \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(\frac{1}{2} + \color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)} \cdot \cos \left(2 \cdot kx\right)\right) + {\sin ky}^{2}}} \]
                                              11. cancel-sign-sub-invN/A

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

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

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

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

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

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

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

                                            Alternative 14: 45.8% accurate, 1.5× speedup?

                                            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.01:\\ \;\;\;\;\left(\sqrt{\frac{1}{\mathsf{fma}\left(\cos \left(2 \cdot kx\right), -0.5, 0.5\right)}} \cdot ky\right) \cdot \sin th\\ \mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-96}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th}{\frac{\sin kx}{ky}}\\ \end{array} \end{array} \]
                                            (FPCore (kx ky th)
                                             :precision binary64
                                             (if (<= (sin kx) -0.01)
                                               (* (* (sqrt (/ 1.0 (fma (cos (* 2.0 kx)) -0.5 0.5))) ky) (sin th))
                                               (if (<= (sin kx) 5e-96) (sin th) (/ (sin th) (/ (sin kx) ky)))))
                                            double code(double kx, double ky, double th) {
                                            	double tmp;
                                            	if (sin(kx) <= -0.01) {
                                            		tmp = (sqrt((1.0 / fma(cos((2.0 * kx)), -0.5, 0.5))) * ky) * sin(th);
                                            	} else if (sin(kx) <= 5e-96) {
                                            		tmp = sin(th);
                                            	} else {
                                            		tmp = sin(th) / (sin(kx) / ky);
                                            	}
                                            	return tmp;
                                            }
                                            
                                            function code(kx, ky, th)
                                            	tmp = 0.0
                                            	if (sin(kx) <= -0.01)
                                            		tmp = Float64(Float64(sqrt(Float64(1.0 / fma(cos(Float64(2.0 * kx)), -0.5, 0.5))) * ky) * sin(th));
                                            	elseif (sin(kx) <= 5e-96)
                                            		tmp = sin(th);
                                            	else
                                            		tmp = Float64(sin(th) / Float64(sin(kx) / ky));
                                            	end
                                            	return tmp
                                            end
                                            
                                            code[kx_, ky_, th_] := If[LessEqual[N[Sin[kx], $MachinePrecision], -0.01], N[(N[(N[Sqrt[N[(1.0 / N[(N[Cos[N[(2.0 * kx), $MachinePrecision]], $MachinePrecision] * -0.5 + 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * ky), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[kx], $MachinePrecision], 5e-96], N[Sin[th], $MachinePrecision], N[(N[Sin[th], $MachinePrecision] / N[(N[Sin[kx], $MachinePrecision] / ky), $MachinePrecision]), $MachinePrecision]]]
                                            
                                            \begin{array}{l}
                                            
                                            \\
                                            \begin{array}{l}
                                            \mathbf{if}\;\sin kx \leq -0.01:\\
                                            \;\;\;\;\left(\sqrt{\frac{1}{\mathsf{fma}\left(\cos \left(2 \cdot kx\right), -0.5, 0.5\right)}} \cdot ky\right) \cdot \sin th\\
                                            
                                            \mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-96}:\\
                                            \;\;\;\;\sin th\\
                                            
                                            \mathbf{else}:\\
                                            \;\;\;\;\frac{\sin th}{\frac{\sin kx}{ky}}\\
                                            
                                            
                                            \end{array}
                                            \end{array}
                                            
                                            Derivation
                                            1. Split input into 3 regimes
                                            2. if (sin.f64 kx) < -0.0100000000000000002

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(\cos \color{blue}{\left(2 \cdot kx\right)}, \mathsf{neg}\left(\frac{1}{2}\right), \frac{1}{2}\right) + {\sin ky}^{2}}} \cdot \sin th \]
                                                15. metadata-eval99.3

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(\cos \left(2 \cdot kx\right), \color{blue}{-0.5}, 0.5\right) + {\sin ky}^{2}}} \cdot \sin th \]
                                              4. Applied rewrites99.3%

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

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

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

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

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

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

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

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

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

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

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

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

                                              if -0.0100000000000000002 < (sin.f64 kx) < 4.99999999999999995e-96

                                              1. Initial program 90.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.f6440.4

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

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

                                              if 4.99999999999999995e-96 < (sin.f64 kx)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(\cos \color{blue}{\left(2 \cdot kx\right)}, \mathsf{neg}\left(\frac{1}{2}\right), \frac{1}{2}\right) + {\sin ky}^{2}}} \cdot \sin th \]
                                                15. metadata-eval88.0

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(\cos \left(2 \cdot kx\right), \color{blue}{-0.5}, 0.5\right) + {\sin ky}^{2}}} \cdot \sin th \]
                                              4. Applied rewrites88.0%

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

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

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

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

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

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

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

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

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

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

                                                  \[\leadsto \frac{\sin th \cdot \sin ky}{\sqrt{\left(\frac{1}{2} + \color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)} \cdot \cos \left(2 \cdot kx\right)\right) + {\sin ky}^{2}}} \]
                                                11. cancel-sign-sub-invN/A

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

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

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

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

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

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

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

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

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

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

                                            Alternative 15: 45.8% accurate, 1.5× speedup?

                                            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.01:\\ \;\;\;\;\left(ky \cdot \sin th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\cos \left(2 \cdot kx\right), -0.5, 0.5\right)}}\\ \mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-96}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th}{\frac{\sin kx}{ky}}\\ \end{array} \end{array} \]
                                            (FPCore (kx ky th)
                                             :precision binary64
                                             (if (<= (sin kx) -0.01)
                                               (* (* ky (sin th)) (sqrt (/ 1.0 (fma (cos (* 2.0 kx)) -0.5 0.5))))
                                               (if (<= (sin kx) 5e-96) (sin th) (/ (sin th) (/ (sin kx) ky)))))
                                            double code(double kx, double ky, double th) {
                                            	double tmp;
                                            	if (sin(kx) <= -0.01) {
                                            		tmp = (ky * sin(th)) * sqrt((1.0 / fma(cos((2.0 * kx)), -0.5, 0.5)));
                                            	} else if (sin(kx) <= 5e-96) {
                                            		tmp = sin(th);
                                            	} else {
                                            		tmp = sin(th) / (sin(kx) / ky);
                                            	}
                                            	return tmp;
                                            }
                                            
                                            function code(kx, ky, th)
                                            	tmp = 0.0
                                            	if (sin(kx) <= -0.01)
                                            		tmp = Float64(Float64(ky * sin(th)) * sqrt(Float64(1.0 / fma(cos(Float64(2.0 * kx)), -0.5, 0.5))));
                                            	elseif (sin(kx) <= 5e-96)
                                            		tmp = sin(th);
                                            	else
                                            		tmp = Float64(sin(th) / Float64(sin(kx) / ky));
                                            	end
                                            	return tmp
                                            end
                                            
                                            code[kx_, ky_, th_] := If[LessEqual[N[Sin[kx], $MachinePrecision], -0.01], N[(N[(ky * N[Sin[th], $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(1.0 / N[(N[Cos[N[(2.0 * kx), $MachinePrecision]], $MachinePrecision] * -0.5 + 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[kx], $MachinePrecision], 5e-96], N[Sin[th], $MachinePrecision], N[(N[Sin[th], $MachinePrecision] / N[(N[Sin[kx], $MachinePrecision] / ky), $MachinePrecision]), $MachinePrecision]]]
                                            
                                            \begin{array}{l}
                                            
                                            \\
                                            \begin{array}{l}
                                            \mathbf{if}\;\sin kx \leq -0.01:\\
                                            \;\;\;\;\left(ky \cdot \sin th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\cos \left(2 \cdot kx\right), -0.5, 0.5\right)}}\\
                                            
                                            \mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-96}:\\
                                            \;\;\;\;\sin th\\
                                            
                                            \mathbf{else}:\\
                                            \;\;\;\;\frac{\sin th}{\frac{\sin kx}{ky}}\\
                                            
                                            
                                            \end{array}
                                            \end{array}
                                            
                                            Derivation
                                            1. Split input into 3 regimes
                                            2. if (sin.f64 kx) < -0.0100000000000000002

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(\cos \color{blue}{\left(2 \cdot kx\right)}, \mathsf{neg}\left(\frac{1}{2}\right), \frac{1}{2}\right) + {\sin ky}^{2}}} \cdot \sin th \]
                                                15. metadata-eval99.3

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(\cos \left(2 \cdot kx\right), \color{blue}{-0.5}, 0.5\right) + {\sin ky}^{2}}} \cdot \sin th \]
                                              4. Applied rewrites99.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                              if -0.0100000000000000002 < (sin.f64 kx) < 4.99999999999999995e-96

                                              1. Initial program 90.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.f6440.4

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

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

                                              if 4.99999999999999995e-96 < (sin.f64 kx)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(\cos \color{blue}{\left(2 \cdot kx\right)}, \mathsf{neg}\left(\frac{1}{2}\right), \frac{1}{2}\right) + {\sin ky}^{2}}} \cdot \sin th \]
                                                15. metadata-eval88.0

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(\cos \left(2 \cdot kx\right), \color{blue}{-0.5}, 0.5\right) + {\sin ky}^{2}}} \cdot \sin th \]
                                              4. Applied rewrites88.0%

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

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

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

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

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

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

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

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

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

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

                                                  \[\leadsto \frac{\sin th \cdot \sin ky}{\sqrt{\left(\frac{1}{2} + \color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)} \cdot \cos \left(2 \cdot kx\right)\right) + {\sin ky}^{2}}} \]
                                                11. cancel-sign-sub-invN/A

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

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

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

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

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

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

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

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

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

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

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

                                            Alternative 16: 66.6% accurate, 1.5× speedup?

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

                                              1. Initial program 95.2%

                                                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                              2. 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. lower-*.f6495.2

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

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

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

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

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

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

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

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

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

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

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

                                                if 9.5000000000000005e-5 < th

                                                1. Initial program 95.4%

                                                  \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                                2. 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. lower-*.f6495.4

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                  Alternative 17: 65.6% accurate, 2.0× speedup?

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

                                                    \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                                  2. 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. lower-*.f6495.2

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

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

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

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

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

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

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

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

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

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

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

                                                      \[\leadsto \sin th \cdot \frac{\color{blue}{ky}}{\mathsf{hypot}\left(\sin kx, ky\right)} \]
                                                    3. Step-by-step derivation
                                                      1. Applied rewrites69.8%

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

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

                                                      Alternative 18: 23.6% accurate, 6.3× speedup?

                                                      \[\begin{array}{l} \\ \sin th \end{array} \]
                                                      (FPCore (kx ky th) :precision binary64 (sin th))
                                                      double code(double kx, double ky, double th) {
                                                      	return sin(th);
                                                      }
                                                      
                                                      real(8) function code(kx, ky, th)
                                                          real(8), intent (in) :: kx
                                                          real(8), intent (in) :: ky
                                                          real(8), intent (in) :: th
                                                          code = sin(th)
                                                      end function
                                                      
                                                      public static double code(double kx, double ky, double th) {
                                                      	return Math.sin(th);
                                                      }
                                                      
                                                      def code(kx, ky, th):
                                                      	return math.sin(th)
                                                      
                                                      function code(kx, ky, th)
                                                      	return sin(th)
                                                      end
                                                      
                                                      function tmp = code(kx, ky, th)
                                                      	tmp = sin(th);
                                                      end
                                                      
                                                      code[kx_, ky_, th_] := N[Sin[th], $MachinePrecision]
                                                      
                                                      \begin{array}{l}
                                                      
                                                      \\
                                                      \sin th
                                                      \end{array}
                                                      
                                                      Derivation
                                                      1. Initial program 95.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.f6424.7

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

                                                        \[\leadsto \color{blue}{\sin th} \]
                                                      6. Add Preprocessing

                                                      Alternative 19: 13.6% accurate, 632.0× speedup?

                                                      \[\begin{array}{l} \\ th \end{array} \]
                                                      (FPCore (kx ky th) :precision binary64 th)
                                                      double code(double kx, double ky, double th) {
                                                      	return th;
                                                      }
                                                      
                                                      real(8) function code(kx, ky, th)
                                                          real(8), intent (in) :: kx
                                                          real(8), intent (in) :: ky
                                                          real(8), intent (in) :: th
                                                          code = th
                                                      end function
                                                      
                                                      public static double code(double kx, double ky, double th) {
                                                      	return th;
                                                      }
                                                      
                                                      def code(kx, ky, th):
                                                      	return th
                                                      
                                                      function code(kx, ky, th)
                                                      	return th
                                                      end
                                                      
                                                      function tmp = code(kx, ky, th)
                                                      	tmp = th;
                                                      end
                                                      
                                                      code[kx_, ky_, th_] := th
                                                      
                                                      \begin{array}{l}
                                                      
                                                      \\
                                                      th
                                                      \end{array}
                                                      
                                                      Derivation
                                                      1. Initial program 95.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                        \[\leadsto th \]
                                                      7. Step-by-step derivation
                                                        1. Applied rewrites15.7%

                                                          \[\leadsto th \]
                                                        2. Add Preprocessing

                                                        Reproduce

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