Toniolo and Linder, Equation (3b), real

Percentage Accurate: 93.9% → 99.7%
Time: 15.6s
Alternatives: 31
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 31 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.9% accurate, 1.0× speedup?

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

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

Alternative 1: 99.7% accurate, 1.2× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 85.9% accurate, 0.2× speedup?

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

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

\mathbf{elif}\;t\_5 \leq -0.1:\\
\;\;\;\;\frac{th \cdot \mathsf{fma}\left(-0.16666666666666666, th \cdot th, 1\right)}{\frac{\sqrt{\mathsf{fma}\left(1 - t\_2, 0.5, 0.5 + -0.5 \cdot t\_3\right)}}{\sin ky}}\\

\mathbf{elif}\;t\_5 \leq 0.2:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\sqrt{t\_4 + ky \cdot ky}}\\

\mathbf{elif}\;t\_5 \leq 0.9991156854772065:\\
\;\;\;\;\frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - t\_3, 0.5, \mathsf{fma}\left(t\_2, -0.5, 0.5\right)\right)}} \cdot \mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\right)\\

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


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

    1. Initial program 90.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.4%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Applied egg-rr99.4%

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

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

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

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

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

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

        \[\leadsto \frac{th \cdot \mathsf{fma}\left(-0.16666666666666666, \color{blue}{th \cdot th}, 1\right)}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, 0.5 + -0.5 \cdot \cos \left(ky + ky\right)\right)}}{\sin ky}} \]
    6. Simplified49.5%

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

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

    1. Initial program 99.4%

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

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

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

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

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

    if 0.20000000000000001 < (/.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.99911568547720653

    1. Initial program 99.2%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Applied egg-rr99.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \mathsf{fma}\left(\cos \left(kx + kx\right), -0.5, 0.5\right)\right)}} \cdot \color{blue}{\mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\right)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification84.9%

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

Alternative 3: 86.4% accurate, 0.2× speedup?

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

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

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

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

\mathbf{elif}\;t\_3 \leq 0.9991156854772065:\\
\;\;\;\;\frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - t\_4, 0.5, \mathsf{fma}\left(t\_2, -0.5, 0.5\right)\right)}} \cdot \mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\right)\\

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


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

    1. Initial program 90.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.4%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Applied egg-rr99.4%

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

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

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

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

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

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

        \[\leadsto \frac{th \cdot \mathsf{fma}\left(-0.16666666666666666, \color{blue}{th \cdot th}, 1\right)}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, 0.5 + -0.5 \cdot \cos \left(ky + ky\right)\right)}}{\sin ky}} \]
    6. Simplified49.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1e-3 < (/.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.99911568547720653

    1. Initial program 99.2%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Applied egg-rr99.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 56.1% accurate, 0.3× speedup?

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

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

\mathbf{elif}\;t\_2 \leq 10^{-262}:\\
\;\;\;\;\sin th \cdot \left(\sin ky \cdot \sqrt{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}\right)\\

\mathbf{elif}\;t\_2 \leq 5 \cdot 10^{-60}:\\
\;\;\;\;\frac{ky \cdot \sin th}{\sin kx}\\

\mathbf{elif}\;t\_2 \leq 0.0004:\\
\;\;\;\;\sin th \cdot \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \mathsf{fma}\left(0.008333333333333333, ky \cdot ky, -0.16666666666666666\right), ky\right)\right)\\

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


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

    1. Initial program 92.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.5%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Applied egg-rr85.5%

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

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

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

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

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

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

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

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

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

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

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

    if 1.00000000000000001e-262 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 5.0000000000000001e-60

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

    1. Initial program 99.1%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Applied egg-rr77.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \mathsf{fma}\left(0.008333333333333333, \color{blue}{ky \cdot ky}, -0.16666666666666666\right), ky\right)\right) \cdot \sin th \]
    9. Simplified79.4%

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

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

    1. Initial program 93.1%

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

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

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

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

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

Alternative 5: 56.1% accurate, 0.3× speedup?

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

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

\mathbf{elif}\;t\_2 \leq 10^{-262}:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\sqrt{\mathsf{fma}\left(-0.5, \cos \left(kx \cdot -2\right), 0.5\right)}}\\

\mathbf{elif}\;t\_2 \leq 5 \cdot 10^{-60}:\\
\;\;\;\;\frac{ky \cdot \sin th}{\sin kx}\\

\mathbf{elif}\;t\_2 \leq 0.0004:\\
\;\;\;\;\sin th \cdot \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \mathsf{fma}\left(0.008333333333333333, ky \cdot ky, -0.16666666666666666\right), ky\right)\right)\\

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


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

    1. Initial program 92.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.5%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Applied egg-rr85.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.00000000000000001e-262 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 5.0000000000000001e-60

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

    1. Initial program 99.1%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Applied egg-rr77.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \mathsf{fma}\left(0.008333333333333333, \color{blue}{ky \cdot ky}, -0.16666666666666666\right), ky\right)\right) \cdot \sin th \]
    9. Simplified79.4%

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

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

    1. Initial program 93.1%

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

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

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

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

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

Alternative 6: 54.4% accurate, 0.3× speedup?

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

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

\mathbf{elif}\;t\_1 \leq 10^{-262}:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\sqrt{\mathsf{fma}\left(-0.5, \cos \left(kx \cdot -2\right), 0.5\right)}}\\

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

\mathbf{elif}\;t\_1 \leq 0.0004:\\
\;\;\;\;\sin th \cdot \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \mathsf{fma}\left(0.008333333333333333, ky \cdot ky, -0.16666666666666666\right), ky\right)\right)\\

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


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

    1. Initial program 92.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.5%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Applied egg-rr85.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.00000000000000001e-262 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 5.0000000000000001e-60

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

    1. Initial program 99.1%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Applied egg-rr77.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \mathsf{fma}\left(0.008333333333333333, \color{blue}{ky \cdot ky}, -0.16666666666666666\right), ky\right)\right) \cdot \sin th \]
    9. Simplified79.4%

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

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

    1. Initial program 93.1%

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

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

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

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

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

Alternative 7: 49.8% accurate, 0.3× speedup?

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

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

\mathbf{elif}\;t\_2 \leq 5 \cdot 10^{-60}:\\
\;\;\;\;\frac{t\_1}{\sin kx}\\

\mathbf{elif}\;t\_2 \leq 0.0004:\\
\;\;\;\;t\_1 \cdot \sqrt{\frac{1}{\mathsf{fma}\left(-0.5, \cos \left(kx \cdot -2\right), 0.5\right)}}\\

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


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

    1. Initial program 95.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.1%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Applied egg-rr77.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\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)}}} \]
      2. lower-*.f64N/A

        \[\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)}} \]
      3. lower-sin.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 93.1%

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

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

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

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

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

Alternative 8: 49.8% accurate, 0.3× speedup?

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

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

\mathbf{elif}\;t\_2 \leq 5 \cdot 10^{-60}:\\
\;\;\;\;\frac{t\_1}{\sin kx}\\

\mathbf{elif}\;t\_2 \leq 0.0004:\\
\;\;\;\;t\_1 \cdot \sqrt{\frac{1}{\mathsf{fma}\left(-0.5, \cos \left(kx \cdot -2\right), 0.5\right)}}\\

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


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

    1. Initial program 95.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.1%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Applied egg-rr77.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\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)}}} \]
      2. lower-*.f64N/A

        \[\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)}} \]
      3. lower-sin.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 93.1%

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

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

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

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

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

Alternative 9: 44.1% accurate, 0.5× speedup?

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

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

\mathbf{elif}\;t\_2 \leq 0.0004:\\
\;\;\;\;t\_1 \cdot \sqrt{\frac{1}{\mathsf{fma}\left(-0.5, \cos \left(kx \cdot -2\right), 0.5\right)}}\\

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


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

    1. Initial program 97.7%

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

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

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

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

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

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

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

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

    1. Initial program 99.1%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Applied egg-rr77.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\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)}}} \]
      2. lower-*.f64N/A

        \[\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)}} \]
      3. lower-sin.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 93.1%

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

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

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

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

Alternative 10: 38.4% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\ t_2 := ky \cdot \sqrt{2}\\ \mathbf{if}\;t\_1 \leq 5 \cdot 10^{-60}:\\ \;\;\;\;\sin th \cdot \left(\sqrt{\frac{1}{\left(kx \cdot kx\right) \cdot \mathsf{fma}\left(kx \cdot kx, \mathsf{fma}\left(kx \cdot kx, 0.08888888888888889, -0.6666666666666666\right), 2\right)}} \cdot t\_2\right)\\ \mathbf{elif}\;t\_1 \leq 2 \cdot 10^{-10}:\\ \;\;\;\;t\_2 \cdot \left(th \cdot \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))))
        (t_2 (* ky (sqrt 2.0))))
   (if (<= t_1 5e-60)
     (*
      (sin th)
      (*
       (sqrt
        (/
         1.0
         (*
          (* kx kx)
          (fma
           (* kx kx)
           (fma (* kx kx) 0.08888888888888889 -0.6666666666666666)
           2.0))))
       t_2))
     (if (<= t_1 2e-10)
       (* t_2 (* th (sqrt (/ 1.0 (- 1.0 (cos (* kx -2.0)))))))
       (sin th)))))
double code(double kx, double ky, double th) {
	double t_1 = sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)));
	double t_2 = ky * sqrt(2.0);
	double tmp;
	if (t_1 <= 5e-60) {
		tmp = sin(th) * (sqrt((1.0 / ((kx * kx) * fma((kx * kx), fma((kx * kx), 0.08888888888888889, -0.6666666666666666), 2.0)))) * t_2);
	} else if (t_1 <= 2e-10) {
		tmp = t_2 * (th * sqrt((1.0 / (1.0 - cos((kx * -2.0))))));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
function code(kx, ky, th)
	t_1 = Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0))))
	t_2 = Float64(ky * sqrt(2.0))
	tmp = 0.0
	if (t_1 <= 5e-60)
		tmp = Float64(sin(th) * Float64(sqrt(Float64(1.0 / Float64(Float64(kx * kx) * fma(Float64(kx * kx), fma(Float64(kx * kx), 0.08888888888888889, -0.6666666666666666), 2.0)))) * t_2));
	elseif (t_1 <= 2e-10)
		tmp = Float64(t_2 * Float64(th * sqrt(Float64(1.0 / Float64(1.0 - cos(Float64(kx * -2.0)))))));
	else
		tmp = sin(th);
	end
	return tmp
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(ky * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, 5e-60], N[(N[Sin[th], $MachinePrecision] * N[(N[Sqrt[N[(1.0 / N[(N[(kx * kx), $MachinePrecision] * N[(N[(kx * kx), $MachinePrecision] * N[(N[(kx * kx), $MachinePrecision] * 0.08888888888888889 + -0.6666666666666666), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2e-10], N[(t$95$2 * N[(th * N[Sqrt[N[(1.0 / N[(1.0 - N[Cos[N[(kx * -2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]]
\begin{array}{l}

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

\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{-10}:\\
\;\;\;\;t\_2 \cdot \left(th \cdot \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}}\right)\\

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


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

    1. Initial program 97.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Applied egg-rr76.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\sqrt{\frac{1}{\left(kx \cdot kx\right) \cdot \mathsf{fma}\left(kx \cdot kx, \mathsf{fma}\left(\color{blue}{kx \cdot kx}, 0.08888888888888889, -0.6666666666666666\right), 2\right)}} \cdot \left(ky \cdot \sqrt{2}\right)\right) \cdot \sin th \]
    9. Simplified28.9%

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

    if 5.0000000000000001e-60 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 2.00000000000000007e-10

    1. Initial program 99.1%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Applied egg-rr77.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 93.1%

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

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

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

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

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

Alternative 11: 38.4% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := ky \cdot \sqrt{2}\\ t_2 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\ \mathbf{if}\;t\_2 \leq 5 \cdot 10^{-60}:\\ \;\;\;\;\sin th \cdot \left(t\_1 \cdot \sqrt{\frac{0.5}{kx \cdot kx}}\right)\\ \mathbf{elif}\;t\_2 \leq 2 \cdot 10^{-10}:\\ \;\;\;\;t\_1 \cdot \left(th \cdot \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (* ky (sqrt 2.0)))
        (t_2 (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0))))))
   (if (<= t_2 5e-60)
     (* (sin th) (* t_1 (sqrt (/ 0.5 (* kx kx)))))
     (if (<= t_2 2e-10)
       (* t_1 (* th (sqrt (/ 1.0 (- 1.0 (cos (* kx -2.0)))))))
       (sin th)))))
double code(double kx, double ky, double th) {
	double t_1 = ky * sqrt(2.0);
	double t_2 = sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)));
	double tmp;
	if (t_2 <= 5e-60) {
		tmp = sin(th) * (t_1 * sqrt((0.5 / (kx * kx))));
	} else if (t_2 <= 2e-10) {
		tmp = t_1 * (th * sqrt((1.0 / (1.0 - cos((kx * -2.0))))));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_1 = ky * sqrt(2.0d0)
    t_2 = sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))
    if (t_2 <= 5d-60) then
        tmp = sin(th) * (t_1 * sqrt((0.5d0 / (kx * kx))))
    else if (t_2 <= 2d-10) then
        tmp = t_1 * (th * sqrt((1.0d0 / (1.0d0 - cos((kx * (-2.0d0)))))))
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double t_1 = ky * Math.sqrt(2.0);
	double t_2 = Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)));
	double tmp;
	if (t_2 <= 5e-60) {
		tmp = Math.sin(th) * (t_1 * Math.sqrt((0.5 / (kx * kx))));
	} else if (t_2 <= 2e-10) {
		tmp = t_1 * (th * Math.sqrt((1.0 / (1.0 - Math.cos((kx * -2.0))))));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = ky * math.sqrt(2.0)
	t_2 = math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))
	tmp = 0
	if t_2 <= 5e-60:
		tmp = math.sin(th) * (t_1 * math.sqrt((0.5 / (kx * kx))))
	elif t_2 <= 2e-10:
		tmp = t_1 * (th * math.sqrt((1.0 / (1.0 - math.cos((kx * -2.0))))))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	t_1 = Float64(ky * sqrt(2.0))
	t_2 = Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0))))
	tmp = 0.0
	if (t_2 <= 5e-60)
		tmp = Float64(sin(th) * Float64(t_1 * sqrt(Float64(0.5 / Float64(kx * kx)))));
	elseif (t_2 <= 2e-10)
		tmp = Float64(t_1 * Float64(th * sqrt(Float64(1.0 / Float64(1.0 - cos(Float64(kx * -2.0)))))));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = ky * sqrt(2.0);
	t_2 = sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)));
	tmp = 0.0;
	if (t_2 <= 5e-60)
		tmp = sin(th) * (t_1 * sqrt((0.5 / (kx * kx))));
	elseif (t_2 <= 2e-10)
		tmp = t_1 * (th * sqrt((1.0 / (1.0 - cos((kx * -2.0))))));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[(ky * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, 5e-60], N[(N[Sin[th], $MachinePrecision] * N[(t$95$1 * N[Sqrt[N[(0.5 / N[(kx * kx), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 2e-10], N[(t$95$1 * N[(th * N[Sqrt[N[(1.0 / N[(1.0 - N[Cos[N[(kx * -2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := ky \cdot \sqrt{2}\\
t_2 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\
\mathbf{if}\;t\_2 \leq 5 \cdot 10^{-60}:\\
\;\;\;\;\sin th \cdot \left(t\_1 \cdot \sqrt{\frac{0.5}{kx \cdot kx}}\right)\\

\mathbf{elif}\;t\_2 \leq 2 \cdot 10^{-10}:\\
\;\;\;\;t\_1 \cdot \left(th \cdot \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}}\right)\\

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


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

    1. Initial program 97.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Applied egg-rr76.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.0000000000000001e-60 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 2.00000000000000007e-10

    1. Initial program 99.1%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Applied egg-rr77.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 93.1%

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

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

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

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

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

Alternative 12: 38.4% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\ \mathbf{if}\;t\_1 \leq 5 \cdot 10^{-60}:\\ \;\;\;\;\sin th \cdot \left(\left(ky \cdot \sqrt{2}\right) \cdot \sqrt{\frac{0.5}{kx \cdot kx}}\right)\\ \mathbf{elif}\;t\_1 \leq 2 \cdot 10^{-10}:\\ \;\;\;\;\sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \cdot \left(ky \cdot \left(th \cdot \sqrt{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0))))))
   (if (<= t_1 5e-60)
     (* (sin th) (* (* ky (sqrt 2.0)) (sqrt (/ 0.5 (* kx kx)))))
     (if (<= t_1 2e-10)
       (* (sqrt (/ 1.0 (- 1.0 (cos (* kx -2.0))))) (* ky (* th (sqrt 2.0))))
       (sin th)))))
double code(double kx, double ky, double th) {
	double t_1 = sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)));
	double tmp;
	if (t_1 <= 5e-60) {
		tmp = sin(th) * ((ky * sqrt(2.0)) * sqrt((0.5 / (kx * kx))));
	} else if (t_1 <= 2e-10) {
		tmp = sqrt((1.0 / (1.0 - cos((kx * -2.0))))) * (ky * (th * sqrt(2.0)));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: t_1
    real(8) :: tmp
    t_1 = sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))
    if (t_1 <= 5d-60) then
        tmp = sin(th) * ((ky * sqrt(2.0d0)) * sqrt((0.5d0 / (kx * kx))))
    else if (t_1 <= 2d-10) then
        tmp = sqrt((1.0d0 / (1.0d0 - cos((kx * (-2.0d0)))))) * (ky * (th * sqrt(2.0d0)))
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double t_1 = Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)));
	double tmp;
	if (t_1 <= 5e-60) {
		tmp = Math.sin(th) * ((ky * Math.sqrt(2.0)) * Math.sqrt((0.5 / (kx * kx))));
	} else if (t_1 <= 2e-10) {
		tmp = Math.sqrt((1.0 / (1.0 - Math.cos((kx * -2.0))))) * (ky * (th * Math.sqrt(2.0)));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))
	tmp = 0
	if t_1 <= 5e-60:
		tmp = math.sin(th) * ((ky * math.sqrt(2.0)) * math.sqrt((0.5 / (kx * kx))))
	elif t_1 <= 2e-10:
		tmp = math.sqrt((1.0 / (1.0 - math.cos((kx * -2.0))))) * (ky * (th * math.sqrt(2.0)))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	t_1 = Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0))))
	tmp = 0.0
	if (t_1 <= 5e-60)
		tmp = Float64(sin(th) * Float64(Float64(ky * sqrt(2.0)) * sqrt(Float64(0.5 / Float64(kx * kx)))));
	elseif (t_1 <= 2e-10)
		tmp = Float64(sqrt(Float64(1.0 / Float64(1.0 - cos(Float64(kx * -2.0))))) * Float64(ky * Float64(th * sqrt(2.0))));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)));
	tmp = 0.0;
	if (t_1 <= 5e-60)
		tmp = sin(th) * ((ky * sqrt(2.0)) * sqrt((0.5 / (kx * kx))));
	elseif (t_1 <= 2e-10)
		tmp = sqrt((1.0 / (1.0 - cos((kx * -2.0))))) * (ky * (th * sqrt(2.0)));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, 5e-60], N[(N[Sin[th], $MachinePrecision] * N[(N[(ky * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(0.5 / N[(kx * kx), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2e-10], N[(N[Sqrt[N[(1.0 / N[(1.0 - N[Cos[N[(kx * -2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(ky * N[(th * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\
\mathbf{if}\;t\_1 \leq 5 \cdot 10^{-60}:\\
\;\;\;\;\sin th \cdot \left(\left(ky \cdot \sqrt{2}\right) \cdot \sqrt{\frac{0.5}{kx \cdot kx}}\right)\\

\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{-10}:\\
\;\;\;\;\sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \cdot \left(ky \cdot \left(th \cdot \sqrt{2}\right)\right)\\

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


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

    1. Initial program 97.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Applied egg-rr76.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.0000000000000001e-60 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 2.00000000000000007e-10

    1. Initial program 99.1%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Applied egg-rr77.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 93.1%

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

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

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

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

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

Alternative 13: 62.9% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := {\sin kx}^{2}\\ \mathbf{if}\;t\_1 \leq 0:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;t\_1 \leq 10^{-9}:\\ \;\;\;\;\frac{\sin th}{\frac{\sqrt{\mathsf{fma}\left(kx, kx, \mathsf{fma}\left(\cos \left(ky + ky\right), -0.5, 0.5\right)\right)}}{\sin ky}}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \left(\sin ky \cdot \sqrt{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}\right)\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (pow (sin kx) 2.0)))
   (if (<= t_1 0.0)
     (sin th)
     (if (<= t_1 1e-9)
       (/
        (sin th)
        (/ (sqrt (fma kx kx (fma (cos (+ ky ky)) -0.5 0.5))) (sin ky)))
       (* (sin th) (* (sin ky) (sqrt (/ 2.0 (- 1.0 (cos (* kx -2.0)))))))))))
double code(double kx, double ky, double th) {
	double t_1 = pow(sin(kx), 2.0);
	double tmp;
	if (t_1 <= 0.0) {
		tmp = sin(th);
	} else if (t_1 <= 1e-9) {
		tmp = sin(th) / (sqrt(fma(kx, kx, fma(cos((ky + ky)), -0.5, 0.5))) / sin(ky));
	} else {
		tmp = sin(th) * (sin(ky) * sqrt((2.0 / (1.0 - cos((kx * -2.0))))));
	}
	return tmp;
}
function code(kx, ky, th)
	t_1 = sin(kx) ^ 2.0
	tmp = 0.0
	if (t_1 <= 0.0)
		tmp = sin(th);
	elseif (t_1 <= 1e-9)
		tmp = Float64(sin(th) / Float64(sqrt(fma(kx, kx, fma(cos(Float64(ky + ky)), -0.5, 0.5))) / sin(ky)));
	else
		tmp = Float64(sin(th) * Float64(sin(ky) * sqrt(Float64(2.0 / Float64(1.0 - cos(Float64(kx * -2.0)))))));
	end
	return tmp
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]}, If[LessEqual[t$95$1, 0.0], N[Sin[th], $MachinePrecision], If[LessEqual[t$95$1, 1e-9], N[(N[Sin[th], $MachinePrecision] / N[(N[Sqrt[N[(kx * kx + N[(N[Cos[N[(ky + ky), $MachinePrecision]], $MachinePrecision] * -0.5 + 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sin[ky], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] * N[Sqrt[N[(2.0 / N[(1.0 - N[Cos[N[(kx * -2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := {\sin kx}^{2}\\
\mathbf{if}\;t\_1 \leq 0:\\
\;\;\;\;\sin th\\

\mathbf{elif}\;t\_1 \leq 10^{-9}:\\
\;\;\;\;\frac{\sin th}{\frac{\sqrt{\mathsf{fma}\left(kx, kx, \mathsf{fma}\left(\cos \left(ky + ky\right), -0.5, 0.5\right)\right)}}{\sin ky}}\\

\mathbf{else}:\\
\;\;\;\;\sin th \cdot \left(\sin ky \cdot \sqrt{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) < 0.0

    1. Initial program 78.0%

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

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

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

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

    if 0.0 < (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) < 1.00000000000000006e-9

    1. Initial program 99.8%

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

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

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

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

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

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

    if 1.00000000000000006e-9 < (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. Applied egg-rr99.0%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(\sqrt{\color{blue}{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}} \cdot \sin ky\right) \cdot \sin th \]
  3. Recombined 3 regimes into one program.
  4. Final simplification69.6%

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

Alternative 14: 62.9% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := {\sin kx}^{2}\\ \mathbf{if}\;t\_1 \leq 0:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;t\_1 \leq 10^{-9}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\sqrt{\mathsf{fma}\left(kx, kx, \mathsf{fma}\left(\cos \left(ky + ky\right), -0.5, 0.5\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \left(\sin ky \cdot \sqrt{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}\right)\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (pow (sin kx) 2.0)))
   (if (<= t_1 0.0)
     (sin th)
     (if (<= t_1 1e-9)
       (*
        (sin ky)
        (/ (sin th) (sqrt (fma kx kx (fma (cos (+ ky ky)) -0.5 0.5)))))
       (* (sin th) (* (sin ky) (sqrt (/ 2.0 (- 1.0 (cos (* kx -2.0)))))))))))
double code(double kx, double ky, double th) {
	double t_1 = pow(sin(kx), 2.0);
	double tmp;
	if (t_1 <= 0.0) {
		tmp = sin(th);
	} else if (t_1 <= 1e-9) {
		tmp = sin(ky) * (sin(th) / sqrt(fma(kx, kx, fma(cos((ky + ky)), -0.5, 0.5))));
	} else {
		tmp = sin(th) * (sin(ky) * sqrt((2.0 / (1.0 - cos((kx * -2.0))))));
	}
	return tmp;
}
function code(kx, ky, th)
	t_1 = sin(kx) ^ 2.0
	tmp = 0.0
	if (t_1 <= 0.0)
		tmp = sin(th);
	elseif (t_1 <= 1e-9)
		tmp = Float64(sin(ky) * Float64(sin(th) / sqrt(fma(kx, kx, fma(cos(Float64(ky + ky)), -0.5, 0.5)))));
	else
		tmp = Float64(sin(th) * Float64(sin(ky) * sqrt(Float64(2.0 / Float64(1.0 - cos(Float64(kx * -2.0)))))));
	end
	return tmp
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]}, If[LessEqual[t$95$1, 0.0], N[Sin[th], $MachinePrecision], If[LessEqual[t$95$1, 1e-9], N[(N[Sin[ky], $MachinePrecision] * N[(N[Sin[th], $MachinePrecision] / N[Sqrt[N[(kx * kx + N[(N[Cos[N[(ky + ky), $MachinePrecision]], $MachinePrecision] * -0.5 + 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] * N[Sqrt[N[(2.0 / N[(1.0 - N[Cos[N[(kx * -2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := {\sin kx}^{2}\\
\mathbf{if}\;t\_1 \leq 0:\\
\;\;\;\;\sin th\\

\mathbf{elif}\;t\_1 \leq 10^{-9}:\\
\;\;\;\;\sin ky \cdot \frac{\sin th}{\sqrt{\mathsf{fma}\left(kx, kx, \mathsf{fma}\left(\cos \left(ky + ky\right), -0.5, 0.5\right)\right)}}\\

\mathbf{else}:\\
\;\;\;\;\sin th \cdot \left(\sin ky \cdot \sqrt{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) < 0.0

    1. Initial program 78.0%

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

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

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

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

    if 0.0 < (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) < 1.00000000000000006e-9

    1. Initial program 99.8%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. lower-*.f6499.8

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
    5. Simplified99.8%

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
    6. Applied egg-rr91.5%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{\mathsf{fma}\left(kx, kx, \mathsf{fma}\left(\cos \left(ky + ky\right), -0.5, 0.5\right)\right)}}} \]

    if 1.00000000000000006e-9 < (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. Applied egg-rr99.0%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, 0.5 + -0.5 \cdot \cos \left(ky + ky\right)\right)}} \cdot \sin ky\right)} \cdot \sin th \]
    4. Taylor expanded in ky around 0

      \[\leadsto \left(\sqrt{\color{blue}{\frac{2}{1 - \cos \left(2 \cdot kx\right)}}} \cdot \sin ky\right) \cdot \sin th \]
    5. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \left(\sqrt{\color{blue}{\frac{2}{1 - \cos \left(2 \cdot kx\right)}}} \cdot \sin ky\right) \cdot \sin th \]
      2. metadata-evalN/A

        \[\leadsto \left(\sqrt{\frac{2}{1 - \cos \left(\color{blue}{\left(\mathsf{neg}\left(-2\right)\right)} \cdot kx\right)}} \cdot \sin ky\right) \cdot \sin th \]
      3. distribute-lft-neg-inN/A

        \[\leadsto \left(\sqrt{\frac{2}{1 - \cos \color{blue}{\left(\mathsf{neg}\left(-2 \cdot kx\right)\right)}}} \cdot \sin ky\right) \cdot \sin th \]
      4. lower--.f64N/A

        \[\leadsto \left(\sqrt{\frac{2}{\color{blue}{1 - \cos \left(\mathsf{neg}\left(-2 \cdot kx\right)\right)}}} \cdot \sin ky\right) \cdot \sin th \]
      5. cos-negN/A

        \[\leadsto \left(\sqrt{\frac{2}{1 - \color{blue}{\cos \left(-2 \cdot kx\right)}}} \cdot \sin ky\right) \cdot \sin th \]
      6. lower-cos.f64N/A

        \[\leadsto \left(\sqrt{\frac{2}{1 - \color{blue}{\cos \left(-2 \cdot kx\right)}}} \cdot \sin ky\right) \cdot \sin th \]
      7. *-commutativeN/A

        \[\leadsto \left(\sqrt{\frac{2}{1 - \cos \color{blue}{\left(kx \cdot -2\right)}}} \cdot \sin ky\right) \cdot \sin th \]
      8. lower-*.f6459.5

        \[\leadsto \left(\sqrt{\frac{2}{1 - \cos \color{blue}{\left(kx \cdot -2\right)}}} \cdot \sin ky\right) \cdot \sin th \]
    6. Simplified59.5%

      \[\leadsto \left(\sqrt{\color{blue}{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}} \cdot \sin ky\right) \cdot \sin th \]
  3. Recombined 3 regimes into one program.
  4. Final simplification69.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;{\sin kx}^{2} \leq 0:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;{\sin kx}^{2} \leq 10^{-9}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\sqrt{\mathsf{fma}\left(kx, kx, \mathsf{fma}\left(\cos \left(ky + ky\right), -0.5, 0.5\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \left(\sin ky \cdot \sqrt{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 15: 44.2% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.001:\\ \;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) 0.001)
   (* ky (/ (sin th) (sin kx)))
   (sin th)))
double code(double kx, double ky, double th) {
	double tmp;
	if ((sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) <= 0.001) {
		tmp = ky * (sin(th) / sin(kx));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if ((sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) <= 0.001d0) then
        tmp = ky * (sin(th) / sin(kx))
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if ((Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) <= 0.001) {
		tmp = ky * (Math.sin(th) / Math.sin(kx));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if (math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))) <= 0.001:
		tmp = ky * (math.sin(th) / math.sin(kx))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 0.001)
		tmp = Float64(ky * Float64(sin(th) / sin(kx)));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if ((sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 0.001)
		tmp = ky * (sin(th) / sin(kx));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 0.001], N[(ky * N[(N[Sin[th], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.001:\\
\;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\

\mathbf{else}:\\
\;\;\;\;\sin th\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 1e-3

    1. Initial program 97.8%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Taylor expanded in ky around 0

      \[\leadsto \color{blue}{ky \cdot \left({ky}^{2} \cdot \left(\frac{-1}{2} \cdot \frac{\sin th}{{\sin kx}^{3}} + \frac{-1}{6} \cdot \frac{\sin th}{\sin kx}\right) + \frac{\sin th}{\sin kx}\right)} \]
    4. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \color{blue}{ky \cdot \left({ky}^{2} \cdot \left(\frac{-1}{2} \cdot \frac{\sin th}{{\sin kx}^{3}} + \frac{-1}{6} \cdot \frac{\sin th}{\sin kx}\right) + \frac{\sin th}{\sin kx}\right)} \]
      2. distribute-lft-inN/A

        \[\leadsto ky \cdot \left(\color{blue}{\left({ky}^{2} \cdot \left(\frac{-1}{2} \cdot \frac{\sin th}{{\sin kx}^{3}}\right) + {ky}^{2} \cdot \left(\frac{-1}{6} \cdot \frac{\sin th}{\sin kx}\right)\right)} + \frac{\sin th}{\sin kx}\right) \]
      3. *-commutativeN/A

        \[\leadsto ky \cdot \left(\left(\color{blue}{\left(\frac{-1}{2} \cdot \frac{\sin th}{{\sin kx}^{3}}\right) \cdot {ky}^{2}} + {ky}^{2} \cdot \left(\frac{-1}{6} \cdot \frac{\sin th}{\sin kx}\right)\right) + \frac{\sin th}{\sin kx}\right) \]
      4. associate-+r+N/A

        \[\leadsto ky \cdot \color{blue}{\left(\left(\frac{-1}{2} \cdot \frac{\sin th}{{\sin kx}^{3}}\right) \cdot {ky}^{2} + \left({ky}^{2} \cdot \left(\frac{-1}{6} \cdot \frac{\sin th}{\sin kx}\right) + \frac{\sin th}{\sin kx}\right)\right)} \]
      5. +-commutativeN/A

        \[\leadsto ky \cdot \color{blue}{\left(\left({ky}^{2} \cdot \left(\frac{-1}{6} \cdot \frac{\sin th}{\sin kx}\right) + \frac{\sin th}{\sin kx}\right) + \left(\frac{-1}{2} \cdot \frac{\sin th}{{\sin kx}^{3}}\right) \cdot {ky}^{2}\right)} \]
    5. Simplified33.2%

      \[\leadsto \color{blue}{ky \cdot \mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right), \frac{\sin th}{\sin kx}, \frac{\left(ky \cdot ky\right) \cdot \left(-0.5 \cdot \sin th\right)}{{\sin kx}^{3}}\right)} \]
    6. Taylor expanded in ky around 0

      \[\leadsto ky \cdot \color{blue}{\frac{\sin th}{\sin kx}} \]
    7. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto ky \cdot \color{blue}{\frac{\sin th}{\sin kx}} \]
      2. lower-sin.f64N/A

        \[\leadsto ky \cdot \frac{\color{blue}{\sin th}}{\sin kx} \]
      3. lower-sin.f6435.5

        \[\leadsto ky \cdot \frac{\sin th}{\color{blue}{\sin kx}} \]
    8. Simplified35.5%

      \[\leadsto ky \cdot \color{blue}{\frac{\sin th}{\sin kx}} \]

    if 1e-3 < (/.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 93.1%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Taylor expanded in kx around 0

      \[\leadsto \color{blue}{\sin th} \]
    4. Step-by-step derivation
      1. lower-sin.f6467.4

        \[\leadsto \color{blue}{\sin th} \]
    5. Simplified67.4%

      \[\leadsto \color{blue}{\sin th} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 16: 38.7% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.001:\\ \;\;\;\;\sin th \cdot \left(\left(ky \cdot \sqrt{2}\right) \cdot \sqrt{\frac{0.5}{kx \cdot kx}}\right)\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) 0.001)
   (* (sin th) (* (* ky (sqrt 2.0)) (sqrt (/ 0.5 (* kx kx)))))
   (sin th)))
double code(double kx, double ky, double th) {
	double tmp;
	if ((sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) <= 0.001) {
		tmp = sin(th) * ((ky * sqrt(2.0)) * sqrt((0.5 / (kx * kx))));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if ((sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) <= 0.001d0) then
        tmp = sin(th) * ((ky * sqrt(2.0d0)) * sqrt((0.5d0 / (kx * kx))))
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if ((Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) <= 0.001) {
		tmp = Math.sin(th) * ((ky * Math.sqrt(2.0)) * Math.sqrt((0.5 / (kx * kx))));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if (math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))) <= 0.001:
		tmp = math.sin(th) * ((ky * math.sqrt(2.0)) * math.sqrt((0.5 / (kx * kx))))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 0.001)
		tmp = Float64(sin(th) * Float64(Float64(ky * sqrt(2.0)) * sqrt(Float64(0.5 / Float64(kx * kx)))));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if ((sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 0.001)
		tmp = sin(th) * ((ky * sqrt(2.0)) * sqrt((0.5 / (kx * kx))));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 0.001], N[(N[Sin[th], $MachinePrecision] * N[(N[(ky * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(0.5 / N[(kx * kx), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.001:\\
\;\;\;\;\sin th \cdot \left(\left(ky \cdot \sqrt{2}\right) \cdot \sqrt{\frac{0.5}{kx \cdot kx}}\right)\\

\mathbf{else}:\\
\;\;\;\;\sin th\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 1e-3

    1. Initial program 97.8%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Applied egg-rr76.9%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, 0.5 + -0.5 \cdot \cos \left(ky + ky\right)\right)}} \cdot \sin ky\right)} \cdot \sin th \]
    4. Taylor expanded in ky around 0

      \[\leadsto \color{blue}{\left(\left(ky \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}}\right)} \cdot \sin th \]
    5. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{\left(\sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}} \cdot \left(ky \cdot \sqrt{2}\right)\right)} \cdot \sin th \]
      2. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(\sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}} \cdot \left(ky \cdot \sqrt{2}\right)\right)} \cdot \sin th \]
      3. lower-sqrt.f64N/A

        \[\leadsto \left(\color{blue}{\sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}}} \cdot \left(ky \cdot \sqrt{2}\right)\right) \cdot \sin th \]
      4. lower-/.f64N/A

        \[\leadsto \left(\sqrt{\color{blue}{\frac{1}{1 - \cos \left(2 \cdot kx\right)}}} \cdot \left(ky \cdot \sqrt{2}\right)\right) \cdot \sin th \]
      5. metadata-evalN/A

        \[\leadsto \left(\sqrt{\frac{1}{1 - \cos \left(\color{blue}{\left(\mathsf{neg}\left(-2\right)\right)} \cdot kx\right)}} \cdot \left(ky \cdot \sqrt{2}\right)\right) \cdot \sin th \]
      6. distribute-lft-neg-inN/A

        \[\leadsto \left(\sqrt{\frac{1}{1 - \cos \color{blue}{\left(\mathsf{neg}\left(-2 \cdot kx\right)\right)}}} \cdot \left(ky \cdot \sqrt{2}\right)\right) \cdot \sin th \]
      7. lower--.f64N/A

        \[\leadsto \left(\sqrt{\frac{1}{\color{blue}{1 - \cos \left(\mathsf{neg}\left(-2 \cdot kx\right)\right)}}} \cdot \left(ky \cdot \sqrt{2}\right)\right) \cdot \sin th \]
      8. cos-negN/A

        \[\leadsto \left(\sqrt{\frac{1}{1 - \color{blue}{\cos \left(-2 \cdot kx\right)}}} \cdot \left(ky \cdot \sqrt{2}\right)\right) \cdot \sin th \]
      9. lower-cos.f64N/A

        \[\leadsto \left(\sqrt{\frac{1}{1 - \color{blue}{\cos \left(-2 \cdot kx\right)}}} \cdot \left(ky \cdot \sqrt{2}\right)\right) \cdot \sin th \]
      10. *-commutativeN/A

        \[\leadsto \left(\sqrt{\frac{1}{1 - \cos \color{blue}{\left(kx \cdot -2\right)}}} \cdot \left(ky \cdot \sqrt{2}\right)\right) \cdot \sin th \]
      11. lower-*.f64N/A

        \[\leadsto \left(\sqrt{\frac{1}{1 - \cos \color{blue}{\left(kx \cdot -2\right)}}} \cdot \left(ky \cdot \sqrt{2}\right)\right) \cdot \sin th \]
      12. lower-*.f64N/A

        \[\leadsto \left(\sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \cdot \color{blue}{\left(ky \cdot \sqrt{2}\right)}\right) \cdot \sin th \]
      13. lower-sqrt.f6441.0

        \[\leadsto \left(\sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \cdot \left(ky \cdot \color{blue}{\sqrt{2}}\right)\right) \cdot \sin th \]
    6. Simplified41.0%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \cdot \left(ky \cdot \sqrt{2}\right)\right)} \cdot \sin th \]
    7. Taylor expanded in kx around 0

      \[\leadsto \left(\sqrt{\color{blue}{\frac{\frac{1}{2}}{{kx}^{2}}}} \cdot \left(ky \cdot \sqrt{2}\right)\right) \cdot \sin th \]
    8. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \left(\sqrt{\color{blue}{\frac{\frac{1}{2}}{{kx}^{2}}}} \cdot \left(ky \cdot \sqrt{2}\right)\right) \cdot \sin th \]
      2. unpow2N/A

        \[\leadsto \left(\sqrt{\frac{\frac{1}{2}}{\color{blue}{kx \cdot kx}}} \cdot \left(ky \cdot \sqrt{2}\right)\right) \cdot \sin th \]
      3. lower-*.f6428.6

        \[\leadsto \left(\sqrt{\frac{0.5}{\color{blue}{kx \cdot kx}}} \cdot \left(ky \cdot \sqrt{2}\right)\right) \cdot \sin th \]
    9. Simplified28.6%

      \[\leadsto \left(\sqrt{\color{blue}{\frac{0.5}{kx \cdot kx}}} \cdot \left(ky \cdot \sqrt{2}\right)\right) \cdot \sin th \]

    if 1e-3 < (/.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 93.1%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Taylor expanded in kx around 0

      \[\leadsto \color{blue}{\sin th} \]
    4. Step-by-step derivation
      1. lower-sin.f6467.4

        \[\leadsto \color{blue}{\sin th} \]
    5. Simplified67.4%

      \[\leadsto \color{blue}{\sin th} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification42.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.001:\\ \;\;\;\;\sin th \cdot \left(\left(ky \cdot \sqrt{2}\right) \cdot \sqrt{\frac{0.5}{kx \cdot kx}}\right)\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
  5. Add Preprocessing

Alternative 17: 99.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;{\sin kx}^{2} \leq 10^{-24}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, 0.5 + -0.5 \cdot \cos \left(ky + ky\right)\right)}}{\sin ky}}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (pow (sin kx) 2.0) 1e-24)
   (* (sin th) (/ (sin ky) (hypot (sin ky) kx)))
   (/
    (sin th)
    (/
     (sqrt (fma (- 1.0 (cos (+ kx kx))) 0.5 (+ 0.5 (* -0.5 (cos (+ ky ky))))))
     (sin ky)))))
double code(double kx, double ky, double th) {
	double tmp;
	if (pow(sin(kx), 2.0) <= 1e-24) {
		tmp = sin(th) * (sin(ky) / hypot(sin(ky), kx));
	} else {
		tmp = sin(th) / (sqrt(fma((1.0 - cos((kx + kx))), 0.5, (0.5 + (-0.5 * cos((ky + ky)))))) / sin(ky));
	}
	return tmp;
}
function code(kx, ky, th)
	tmp = 0.0
	if ((sin(kx) ^ 2.0) <= 1e-24)
		tmp = Float64(sin(th) * Float64(sin(ky) / hypot(sin(ky), kx)));
	else
		tmp = Float64(sin(th) / Float64(sqrt(fma(Float64(1.0 - cos(Float64(kx + kx))), 0.5, Float64(0.5 + Float64(-0.5 * cos(Float64(ky + ky)))))) / sin(ky)));
	end
	return tmp
end
code[kx_, ky_, th_] := If[LessEqual[N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision], 1e-24], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + kx ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[th], $MachinePrecision] / N[(N[Sqrt[N[(N[(1.0 - N[Cos[N[(kx + kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 0.5 + N[(0.5 + N[(-0.5 * N[Cos[N[(ky + ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sin[ky], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;{\sin kx}^{2} \leq 10^{-24}:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{\sin th}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, 0.5 + -0.5 \cdot \cos \left(ky + ky\right)\right)}}{\sin ky}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) < 9.99999999999999924e-25

    1. Initial program 92.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Taylor expanded in kx around 0

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. lower-*.f6492.7

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
    5. Simplified92.7%

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
    6. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. lift-sin.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\color{blue}{\sin ky}}^{2}}} \cdot \sin th \]
      3. pow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + \color{blue}{\sin ky \cdot \sin ky}}} \cdot \sin th \]
      4. +-commutativeN/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky + kx \cdot kx}}} \cdot \sin th \]
      5. lift-*.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{kx \cdot kx}}} \cdot \sin th \]
      6. lower-hypot.f6499.8

        \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, kx\right)}} \cdot \sin th \]
    7. Applied egg-rr99.8%

      \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, kx\right)}} \cdot \sin th \]

    if 9.99999999999999924e-25 < (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. Applied egg-rr99.1%

      \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, 0.5 + -0.5 \cdot \cos \left(ky + ky\right)\right)}}{\sin ky}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;{\sin kx}^{2} \leq 10^{-24}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, 0.5 + -0.5 \cdot \cos \left(ky + ky\right)\right)}}{\sin ky}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 18: 99.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;{\sin kx}^{2} \leq 10^{-24}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \mathsf{fma}\left(\cos \left(kx + kx\right), -0.5, 0.5\right)\right)}}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (pow (sin kx) 2.0) 1e-24)
   (* (sin th) (/ (sin ky) (hypot (sin ky) kx)))
   (*
    (sin th)
    (/
     (sin ky)
     (sqrt
      (fma (- 1.0 (cos (+ ky ky))) 0.5 (fma (cos (+ kx kx)) -0.5 0.5)))))))
double code(double kx, double ky, double th) {
	double tmp;
	if (pow(sin(kx), 2.0) <= 1e-24) {
		tmp = sin(th) * (sin(ky) / hypot(sin(ky), kx));
	} else {
		tmp = sin(th) * (sin(ky) / sqrt(fma((1.0 - cos((ky + ky))), 0.5, fma(cos((kx + kx)), -0.5, 0.5))));
	}
	return tmp;
}
function code(kx, ky, th)
	tmp = 0.0
	if ((sin(kx) ^ 2.0) <= 1e-24)
		tmp = Float64(sin(th) * Float64(sin(ky) / hypot(sin(ky), kx)));
	else
		tmp = Float64(sin(th) * Float64(sin(ky) / sqrt(fma(Float64(1.0 - cos(Float64(ky + ky))), 0.5, fma(cos(Float64(kx + kx)), -0.5, 0.5)))));
	end
	return tmp
end
code[kx_, ky_, th_] := If[LessEqual[N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision], 1e-24], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + kx ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(1.0 - N[Cos[N[(ky + ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 0.5 + N[(N[Cos[N[(kx + kx), $MachinePrecision]], $MachinePrecision] * -0.5 + 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;{\sin kx}^{2} \leq 10^{-24}:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)}\\

\mathbf{else}:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \mathsf{fma}\left(\cos \left(kx + kx\right), -0.5, 0.5\right)\right)}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) < 9.99999999999999924e-25

    1. Initial program 92.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Taylor expanded in kx around 0

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. lower-*.f6492.7

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
    5. Simplified92.7%

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
    6. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. lift-sin.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\color{blue}{\sin ky}}^{2}}} \cdot \sin th \]
      3. pow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + \color{blue}{\sin ky \cdot \sin ky}}} \cdot \sin th \]
      4. +-commutativeN/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky + kx \cdot kx}}} \cdot \sin th \]
      5. lift-*.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{kx \cdot kx}}} \cdot \sin th \]
      6. lower-hypot.f6499.8

        \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, kx\right)}} \cdot \sin th \]
    7. Applied egg-rr99.8%

      \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, kx\right)}} \cdot \sin th \]

    if 9.99999999999999924e-25 < (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. Applied egg-rr99.1%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, 0.5 + -0.5 \cdot \cos \left(ky + ky\right)\right)}} \cdot \sin ky\right)} \cdot \sin th \]
    4. Applied egg-rr12.3%

      \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \mathsf{fma}\left(\cos \left(ky + ky\right), -0.5, 0.5\right)\right)}} \cdot \sin th} \]
    5. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \cos \color{blue}{\left(ky + ky\right)} \cdot \frac{-1}{2} + \frac{1}{2}\right)}} \cdot \sin th \]
      2. lift-cos.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \color{blue}{\cos \left(ky + ky\right)} \cdot \frac{-1}{2} + \frac{1}{2}\right)}} \cdot \sin th \]
      3. lift-fma.f6412.3

        \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \color{blue}{\mathsf{fma}\left(\cos \left(ky + ky\right), -0.5, 0.5\right)}\right)}} \cdot \sin th \]
      4. lift-+.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \color{blue}{\left(ky + ky\right)}, \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
      5. flip-+N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \color{blue}{\left(\frac{ky \cdot ky - ky \cdot ky}{ky - ky}\right)}, \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
      6. lift-*.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \left(\frac{\color{blue}{ky \cdot ky} - ky \cdot ky}{ky - ky}\right), \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
      7. lift-*.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \left(\frac{ky \cdot ky - \color{blue}{ky \cdot ky}}{ky - ky}\right), \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
      8. +-inversesN/A

        \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \left(\frac{\color{blue}{0}}{ky - ky}\right), \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
      9. +-inversesN/A

        \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \left(\frac{\color{blue}{kx \cdot kx - kx \cdot kx}}{ky - ky}\right), \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
      10. +-inversesN/A

        \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \left(\frac{kx \cdot kx - kx \cdot kx}{\color{blue}{0}}\right), \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
      11. +-inversesN/A

        \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \left(\frac{kx \cdot kx - kx \cdot kx}{\color{blue}{kx - kx}}\right), \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
      12. flip-+N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \color{blue}{\left(kx + kx\right)}, \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
      13. lift-+.f6499.1

        \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \mathsf{fma}\left(\cos \color{blue}{\left(kx + kx\right)}, -0.5, 0.5\right)\right)}} \cdot \sin th \]
    6. Applied egg-rr99.1%

      \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \color{blue}{\mathsf{fma}\left(\cos \left(kx + kx\right), -0.5, 0.5\right)}\right)}} \cdot \sin th \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;{\sin kx}^{2} \leq 10^{-24}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \mathsf{fma}\left(\cos \left(kx + kx\right), -0.5, 0.5\right)\right)}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 19: 15.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin th \cdot \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 4 \cdot 10^{-305}:\\ \;\;\;\;-0.16666666666666666 \cdot \left(th \cdot \left(th \cdot th\right)\right)\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<=
      (*
       (sin th)
       (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))))
      4e-305)
   (* -0.16666666666666666 (* th (* th th)))
   th))
double code(double kx, double ky, double th) {
	double tmp;
	if ((sin(th) * (sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0))))) <= 4e-305) {
		tmp = -0.16666666666666666 * (th * (th * th));
	} else {
		tmp = th;
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if ((sin(th) * (sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0))))) <= 4d-305) then
        tmp = (-0.16666666666666666d0) * (th * (th * th))
    else
        tmp = th
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if ((Math.sin(th) * (Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0))))) <= 4e-305) {
		tmp = -0.16666666666666666 * (th * (th * th));
	} else {
		tmp = th;
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if (math.sin(th) * (math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0))))) <= 4e-305:
		tmp = -0.16666666666666666 * (th * (th * th))
	else:
		tmp = th
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (Float64(sin(th) * Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0))))) <= 4e-305)
		tmp = Float64(-0.16666666666666666 * Float64(th * Float64(th * th)));
	else
		tmp = th;
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if ((sin(th) * (sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0))))) <= 4e-305)
		tmp = -0.16666666666666666 * (th * (th * th));
	else
		tmp = th;
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[N[(N[Sin[th], $MachinePrecision] * 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]), $MachinePrecision], 4e-305], N[(-0.16666666666666666 * N[(th * N[(th * th), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], th]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\sin th \cdot \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 4 \cdot 10^{-305}:\\
\;\;\;\;-0.16666666666666666 \cdot \left(th \cdot \left(th \cdot th\right)\right)\\

\mathbf{else}:\\
\;\;\;\;th\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) (sin.f64 th)) < 3.99999999999999999e-305

    1. Initial program 96.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.f6423.4

        \[\leadsto \color{blue}{\sin th} \]
    5. Simplified23.4%

      \[\leadsto \color{blue}{\sin th} \]
    6. Taylor expanded in th around 0

      \[\leadsto \color{blue}{th \cdot \left(1 + \frac{-1}{6} \cdot {th}^{2}\right)} \]
    7. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \color{blue}{th \cdot \left(1 + \frac{-1}{6} \cdot {th}^{2}\right)} \]
      2. +-commutativeN/A

        \[\leadsto th \cdot \color{blue}{\left(\frac{-1}{6} \cdot {th}^{2} + 1\right)} \]
      3. lower-fma.f64N/A

        \[\leadsto th \cdot \color{blue}{\mathsf{fma}\left(\frac{-1}{6}, {th}^{2}, 1\right)} \]
      4. unpow2N/A

        \[\leadsto th \cdot \mathsf{fma}\left(\frac{-1}{6}, \color{blue}{th \cdot th}, 1\right) \]
      5. lower-*.f6413.8

        \[\leadsto th \cdot \mathsf{fma}\left(-0.16666666666666666, \color{blue}{th \cdot th}, 1\right) \]
    8. Simplified13.8%

      \[\leadsto \color{blue}{th \cdot \mathsf{fma}\left(-0.16666666666666666, th \cdot th, 1\right)} \]
    9. Taylor expanded in th around inf

      \[\leadsto \color{blue}{\frac{-1}{6} \cdot {th}^{3}} \]
    10. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \color{blue}{\frac{-1}{6} \cdot {th}^{3}} \]
      2. cube-multN/A

        \[\leadsto \frac{-1}{6} \cdot \color{blue}{\left(th \cdot \left(th \cdot th\right)\right)} \]
      3. unpow2N/A

        \[\leadsto \frac{-1}{6} \cdot \left(th \cdot \color{blue}{{th}^{2}}\right) \]
      4. lower-*.f64N/A

        \[\leadsto \frac{-1}{6} \cdot \color{blue}{\left(th \cdot {th}^{2}\right)} \]
      5. unpow2N/A

        \[\leadsto \frac{-1}{6} \cdot \left(th \cdot \color{blue}{\left(th \cdot th\right)}\right) \]
      6. lower-*.f6418.7

        \[\leadsto -0.16666666666666666 \cdot \left(th \cdot \color{blue}{\left(th \cdot th\right)}\right) \]
    11. Simplified18.7%

      \[\leadsto \color{blue}{-0.16666666666666666 \cdot \left(th \cdot \left(th \cdot th\right)\right)} \]

    if 3.99999999999999999e-305 < (*.f64 (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) (sin.f64 th))

    1. Initial program 95.5%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Taylor expanded in kx around 0

      \[\leadsto \color{blue}{\sin th} \]
    4. Step-by-step derivation
      1. lower-sin.f6428.9

        \[\leadsto \color{blue}{\sin th} \]
    5. Simplified28.9%

      \[\leadsto \color{blue}{\sin th} \]
    6. Taylor expanded in th around 0

      \[\leadsto \color{blue}{th \cdot \left(1 + \frac{-1}{6} \cdot {th}^{2}\right)} \]
    7. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \color{blue}{th \cdot \left(1 + \frac{-1}{6} \cdot {th}^{2}\right)} \]
      2. +-commutativeN/A

        \[\leadsto th \cdot \color{blue}{\left(\frac{-1}{6} \cdot {th}^{2} + 1\right)} \]
      3. lower-fma.f64N/A

        \[\leadsto th \cdot \color{blue}{\mathsf{fma}\left(\frac{-1}{6}, {th}^{2}, 1\right)} \]
      4. unpow2N/A

        \[\leadsto th \cdot \mathsf{fma}\left(\frac{-1}{6}, \color{blue}{th \cdot th}, 1\right) \]
      5. lower-*.f6415.7

        \[\leadsto th \cdot \mathsf{fma}\left(-0.16666666666666666, \color{blue}{th \cdot th}, 1\right) \]
    8. Simplified15.7%

      \[\leadsto \color{blue}{th \cdot \mathsf{fma}\left(-0.16666666666666666, th \cdot th, 1\right)} \]
    9. Taylor expanded in th around 0

      \[\leadsto th \cdot \color{blue}{1} \]
    10. Step-by-step derivation
      1. Simplified16.7%

        \[\leadsto th \cdot \color{blue}{1} \]
      2. Step-by-step derivation
        1. *-rgt-identity16.7

          \[\leadsto \color{blue}{th} \]
      3. Applied egg-rr16.7%

        \[\leadsto \color{blue}{th} \]
    11. Recombined 2 regimes into one program.
    12. Final simplification17.8%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\sin th \cdot \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 4 \cdot 10^{-305}:\\ \;\;\;\;-0.16666666666666666 \cdot \left(th \cdot \left(th \cdot th\right)\right)\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \]
    13. Add Preprocessing

    Alternative 20: 35.6% accurate, 1.0× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.001:\\ \;\;\;\;\frac{ky \cdot \sin th}{kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
    (FPCore (kx ky th)
     :precision binary64
     (if (<= (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) 0.001)
       (/ (* ky (sin th)) kx)
       (sin th)))
    double code(double kx, double ky, double th) {
    	double tmp;
    	if ((sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) <= 0.001) {
    		tmp = (ky * sin(th)) / kx;
    	} else {
    		tmp = sin(th);
    	}
    	return tmp;
    }
    
    real(8) function code(kx, ky, th)
        real(8), intent (in) :: kx
        real(8), intent (in) :: ky
        real(8), intent (in) :: th
        real(8) :: tmp
        if ((sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) <= 0.001d0) then
            tmp = (ky * sin(th)) / kx
        else
            tmp = sin(th)
        end if
        code = tmp
    end function
    
    public static double code(double kx, double ky, double th) {
    	double tmp;
    	if ((Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) <= 0.001) {
    		tmp = (ky * Math.sin(th)) / kx;
    	} else {
    		tmp = Math.sin(th);
    	}
    	return tmp;
    }
    
    def code(kx, ky, th):
    	tmp = 0
    	if (math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))) <= 0.001:
    		tmp = (ky * math.sin(th)) / kx
    	else:
    		tmp = math.sin(th)
    	return tmp
    
    function code(kx, ky, th)
    	tmp = 0.0
    	if (Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 0.001)
    		tmp = Float64(Float64(ky * sin(th)) / kx);
    	else
    		tmp = sin(th);
    	end
    	return tmp
    end
    
    function tmp_2 = code(kx, ky, th)
    	tmp = 0.0;
    	if ((sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 0.001)
    		tmp = (ky * sin(th)) / kx;
    	else
    		tmp = sin(th);
    	end
    	tmp_2 = tmp;
    end
    
    code[kx_, ky_, th_] := If[LessEqual[N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 0.001], N[(N[(ky * N[Sin[th], $MachinePrecision]), $MachinePrecision] / kx), $MachinePrecision], N[Sin[th], $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.001:\\
    \;\;\;\;\frac{ky \cdot \sin th}{kx}\\
    
    \mathbf{else}:\\
    \;\;\;\;\sin th\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 1e-3

      1. Initial program 97.8%

        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      2. Add Preprocessing
      3. Taylor expanded in kx around 0

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
      4. Step-by-step derivation
        1. unpow2N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
        2. lower-*.f6450.3

          \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
      5. Simplified50.3%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
      6. Taylor expanded in ky around 0

        \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{kx}} \]
      7. Step-by-step derivation
        1. lower-/.f64N/A

          \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{kx}} \]
        2. lower-*.f64N/A

          \[\leadsto \frac{\color{blue}{ky \cdot \sin th}}{kx} \]
        3. lower-sin.f6424.0

          \[\leadsto \frac{ky \cdot \color{blue}{\sin th}}{kx} \]
      8. Simplified24.0%

        \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{kx}} \]

      if 1e-3 < (/.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 93.1%

        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      2. Add Preprocessing
      3. Taylor expanded in kx around 0

        \[\leadsto \color{blue}{\sin th} \]
      4. Step-by-step derivation
        1. lower-sin.f6467.4

          \[\leadsto \color{blue}{\sin th} \]
      5. Simplified67.4%

        \[\leadsto \color{blue}{\sin th} \]
    3. Recombined 2 regimes into one program.
    4. Add Preprocessing

    Alternative 21: 36.2% accurate, 1.0× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.001:\\ \;\;\;\;\sin th \cdot \frac{ky}{kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
    (FPCore (kx ky th)
     :precision binary64
     (if (<= (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) 0.001)
       (* (sin th) (/ ky kx))
       (sin th)))
    double code(double kx, double ky, double th) {
    	double tmp;
    	if ((sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) <= 0.001) {
    		tmp = sin(th) * (ky / kx);
    	} else {
    		tmp = sin(th);
    	}
    	return tmp;
    }
    
    real(8) function code(kx, ky, th)
        real(8), intent (in) :: kx
        real(8), intent (in) :: ky
        real(8), intent (in) :: th
        real(8) :: tmp
        if ((sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) <= 0.001d0) then
            tmp = sin(th) * (ky / kx)
        else
            tmp = sin(th)
        end if
        code = tmp
    end function
    
    public static double code(double kx, double ky, double th) {
    	double tmp;
    	if ((Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) <= 0.001) {
    		tmp = Math.sin(th) * (ky / kx);
    	} else {
    		tmp = Math.sin(th);
    	}
    	return tmp;
    }
    
    def code(kx, ky, th):
    	tmp = 0
    	if (math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))) <= 0.001:
    		tmp = math.sin(th) * (ky / kx)
    	else:
    		tmp = math.sin(th)
    	return tmp
    
    function code(kx, ky, th)
    	tmp = 0.0
    	if (Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 0.001)
    		tmp = Float64(sin(th) * Float64(ky / kx));
    	else
    		tmp = sin(th);
    	end
    	return tmp
    end
    
    function tmp_2 = code(kx, ky, th)
    	tmp = 0.0;
    	if ((sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 0.001)
    		tmp = sin(th) * (ky / kx);
    	else
    		tmp = sin(th);
    	end
    	tmp_2 = tmp;
    end
    
    code[kx_, ky_, th_] := If[LessEqual[N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 0.001], N[(N[Sin[th], $MachinePrecision] * N[(ky / kx), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.001:\\
    \;\;\;\;\sin th \cdot \frac{ky}{kx}\\
    
    \mathbf{else}:\\
    \;\;\;\;\sin th\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 1e-3

      1. Initial program 97.8%

        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      2. Add Preprocessing
      3. Taylor expanded in kx around 0

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
      4. Step-by-step derivation
        1. unpow2N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
        2. lower-*.f6450.3

          \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
      5. Simplified50.3%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
      6. Taylor expanded in ky around 0

        \[\leadsto \color{blue}{\frac{ky}{kx}} \cdot \sin th \]
      7. Step-by-step derivation
        1. lower-/.f6424.0

          \[\leadsto \color{blue}{\frac{ky}{kx}} \cdot \sin th \]
      8. Simplified24.0%

        \[\leadsto \color{blue}{\frac{ky}{kx}} \cdot \sin th \]

      if 1e-3 < (/.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 93.1%

        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      2. Add Preprocessing
      3. Taylor expanded in kx around 0

        \[\leadsto \color{blue}{\sin th} \]
      4. Step-by-step derivation
        1. lower-sin.f6467.4

          \[\leadsto \color{blue}{\sin th} \]
      5. Simplified67.4%

        \[\leadsto \color{blue}{\sin th} \]
    3. Recombined 2 regimes into one program.
    4. Final simplification39.1%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.001:\\ \;\;\;\;\sin th \cdot \frac{ky}{kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
    5. Add Preprocessing

    Alternative 22: 31.2% accurate, 1.0× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 6 \cdot 10^{-77}:\\ \;\;\;\;-0.16666666666666666 \cdot \left(th \cdot \left(th \cdot th\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
    (FPCore (kx ky th)
     :precision binary64
     (if (<= (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) 6e-77)
       (* -0.16666666666666666 (* th (* th th)))
       (sin th)))
    double code(double kx, double ky, double th) {
    	double tmp;
    	if ((sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) <= 6e-77) {
    		tmp = -0.16666666666666666 * (th * (th * th));
    	} else {
    		tmp = sin(th);
    	}
    	return tmp;
    }
    
    real(8) function code(kx, ky, th)
        real(8), intent (in) :: kx
        real(8), intent (in) :: ky
        real(8), intent (in) :: th
        real(8) :: tmp
        if ((sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) <= 6d-77) then
            tmp = (-0.16666666666666666d0) * (th * (th * th))
        else
            tmp = sin(th)
        end if
        code = tmp
    end function
    
    public static double code(double kx, double ky, double th) {
    	double tmp;
    	if ((Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) <= 6e-77) {
    		tmp = -0.16666666666666666 * (th * (th * th));
    	} else {
    		tmp = Math.sin(th);
    	}
    	return tmp;
    }
    
    def code(kx, ky, th):
    	tmp = 0
    	if (math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))) <= 6e-77:
    		tmp = -0.16666666666666666 * (th * (th * th))
    	else:
    		tmp = math.sin(th)
    	return tmp
    
    function code(kx, ky, th)
    	tmp = 0.0
    	if (Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 6e-77)
    		tmp = Float64(-0.16666666666666666 * Float64(th * Float64(th * th)));
    	else
    		tmp = sin(th);
    	end
    	return tmp
    end
    
    function tmp_2 = code(kx, ky, th)
    	tmp = 0.0;
    	if ((sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 6e-77)
    		tmp = -0.16666666666666666 * (th * (th * th));
    	else
    		tmp = sin(th);
    	end
    	tmp_2 = tmp;
    end
    
    code[kx_, ky_, th_] := If[LessEqual[N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 6e-77], N[(-0.16666666666666666 * N[(th * N[(th * th), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 6 \cdot 10^{-77}:\\
    \;\;\;\;-0.16666666666666666 \cdot \left(th \cdot \left(th \cdot th\right)\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;\sin th\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 6.00000000000000033e-77

      1. Initial program 97.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.f643.5

          \[\leadsto \color{blue}{\sin th} \]
      5. Simplified3.5%

        \[\leadsto \color{blue}{\sin th} \]
      6. Taylor expanded in th around 0

        \[\leadsto \color{blue}{th \cdot \left(1 + \frac{-1}{6} \cdot {th}^{2}\right)} \]
      7. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto \color{blue}{th \cdot \left(1 + \frac{-1}{6} \cdot {th}^{2}\right)} \]
        2. +-commutativeN/A

          \[\leadsto th \cdot \color{blue}{\left(\frac{-1}{6} \cdot {th}^{2} + 1\right)} \]
        3. lower-fma.f64N/A

          \[\leadsto th \cdot \color{blue}{\mathsf{fma}\left(\frac{-1}{6}, {th}^{2}, 1\right)} \]
        4. unpow2N/A

          \[\leadsto th \cdot \mathsf{fma}\left(\frac{-1}{6}, \color{blue}{th \cdot th}, 1\right) \]
        5. lower-*.f643.4

          \[\leadsto th \cdot \mathsf{fma}\left(-0.16666666666666666, \color{blue}{th \cdot th}, 1\right) \]
      8. Simplified3.4%

        \[\leadsto \color{blue}{th \cdot \mathsf{fma}\left(-0.16666666666666666, th \cdot th, 1\right)} \]
      9. Taylor expanded in th around inf

        \[\leadsto \color{blue}{\frac{-1}{6} \cdot {th}^{3}} \]
      10. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto \color{blue}{\frac{-1}{6} \cdot {th}^{3}} \]
        2. cube-multN/A

          \[\leadsto \frac{-1}{6} \cdot \color{blue}{\left(th \cdot \left(th \cdot th\right)\right)} \]
        3. unpow2N/A

          \[\leadsto \frac{-1}{6} \cdot \left(th \cdot \color{blue}{{th}^{2}}\right) \]
        4. lower-*.f64N/A

          \[\leadsto \frac{-1}{6} \cdot \color{blue}{\left(th \cdot {th}^{2}\right)} \]
        5. unpow2N/A

          \[\leadsto \frac{-1}{6} \cdot \left(th \cdot \color{blue}{\left(th \cdot th\right)}\right) \]
        6. lower-*.f6417.5

          \[\leadsto -0.16666666666666666 \cdot \left(th \cdot \color{blue}{\left(th \cdot th\right)}\right) \]
      11. Simplified17.5%

        \[\leadsto \color{blue}{-0.16666666666666666 \cdot \left(th \cdot \left(th \cdot th\right)\right)} \]

      if 6.00000000000000033e-77 < (/.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 93.9%

        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      2. Add Preprocessing
      3. Taylor expanded in kx around 0

        \[\leadsto \color{blue}{\sin th} \]
      4. Step-by-step derivation
        1. lower-sin.f6459.3

          \[\leadsto \color{blue}{\sin th} \]
      5. Simplified59.3%

        \[\leadsto \color{blue}{\sin th} \]
    3. Recombined 2 regimes into one program.
    4. Add Preprocessing

    Alternative 23: 79.3% accurate, 1.0× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;{\sin kx}^{2} \leq 10^{-9}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \left(\sin ky \cdot \sqrt{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}\right)\\ \end{array} \end{array} \]
    (FPCore (kx ky th)
     :precision binary64
     (if (<= (pow (sin kx) 2.0) 1e-9)
       (* (sin th) (/ (sin ky) (hypot (sin ky) kx)))
       (* (sin th) (* (sin ky) (sqrt (/ 2.0 (- 1.0 (cos (* kx -2.0)))))))))
    double code(double kx, double ky, double th) {
    	double tmp;
    	if (pow(sin(kx), 2.0) <= 1e-9) {
    		tmp = sin(th) * (sin(ky) / hypot(sin(ky), kx));
    	} else {
    		tmp = sin(th) * (sin(ky) * sqrt((2.0 / (1.0 - cos((kx * -2.0))))));
    	}
    	return tmp;
    }
    
    public static double code(double kx, double ky, double th) {
    	double tmp;
    	if (Math.pow(Math.sin(kx), 2.0) <= 1e-9) {
    		tmp = Math.sin(th) * (Math.sin(ky) / Math.hypot(Math.sin(ky), kx));
    	} else {
    		tmp = Math.sin(th) * (Math.sin(ky) * Math.sqrt((2.0 / (1.0 - Math.cos((kx * -2.0))))));
    	}
    	return tmp;
    }
    
    def code(kx, ky, th):
    	tmp = 0
    	if math.pow(math.sin(kx), 2.0) <= 1e-9:
    		tmp = math.sin(th) * (math.sin(ky) / math.hypot(math.sin(ky), kx))
    	else:
    		tmp = math.sin(th) * (math.sin(ky) * math.sqrt((2.0 / (1.0 - math.cos((kx * -2.0))))))
    	return tmp
    
    function code(kx, ky, th)
    	tmp = 0.0
    	if ((sin(kx) ^ 2.0) <= 1e-9)
    		tmp = Float64(sin(th) * Float64(sin(ky) / hypot(sin(ky), kx)));
    	else
    		tmp = Float64(sin(th) * Float64(sin(ky) * sqrt(Float64(2.0 / Float64(1.0 - cos(Float64(kx * -2.0)))))));
    	end
    	return tmp
    end
    
    function tmp_2 = code(kx, ky, th)
    	tmp = 0.0;
    	if ((sin(kx) ^ 2.0) <= 1e-9)
    		tmp = sin(th) * (sin(ky) / hypot(sin(ky), kx));
    	else
    		tmp = sin(th) * (sin(ky) * sqrt((2.0 / (1.0 - cos((kx * -2.0))))));
    	end
    	tmp_2 = tmp;
    end
    
    code[kx_, ky_, th_] := If[LessEqual[N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision], 1e-9], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + kx ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] * N[Sqrt[N[(2.0 / N[(1.0 - N[Cos[N[(kx * -2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;{\sin kx}^{2} \leq 10^{-9}:\\
    \;\;\;\;\sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)}\\
    
    \mathbf{else}:\\
    \;\;\;\;\sin th \cdot \left(\sin ky \cdot \sqrt{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}\right)\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) < 1.00000000000000006e-9

      1. Initial program 92.8%

        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      2. Add Preprocessing
      3. Taylor expanded in kx around 0

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
      4. Step-by-step derivation
        1. unpow2N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
        2. lower-*.f6492.8

          \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
      5. Simplified92.8%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
      6. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
        2. lift-sin.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\color{blue}{\sin ky}}^{2}}} \cdot \sin th \]
        3. pow2N/A

          \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + \color{blue}{\sin ky \cdot \sin ky}}} \cdot \sin th \]
        4. +-commutativeN/A

          \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky + kx \cdot kx}}} \cdot \sin th \]
        5. lift-*.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{kx \cdot kx}}} \cdot \sin th \]
        6. lower-hypot.f6499.8

          \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, kx\right)}} \cdot \sin th \]
      7. Applied egg-rr99.8%

        \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, kx\right)}} \cdot \sin th \]

      if 1.00000000000000006e-9 < (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. Applied egg-rr99.0%

        \[\leadsto \color{blue}{\left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, 0.5 + -0.5 \cdot \cos \left(ky + ky\right)\right)}} \cdot \sin ky\right)} \cdot \sin th \]
      4. Taylor expanded in ky around 0

        \[\leadsto \left(\sqrt{\color{blue}{\frac{2}{1 - \cos \left(2 \cdot kx\right)}}} \cdot \sin ky\right) \cdot \sin th \]
      5. Step-by-step derivation
        1. lower-/.f64N/A

          \[\leadsto \left(\sqrt{\color{blue}{\frac{2}{1 - \cos \left(2 \cdot kx\right)}}} \cdot \sin ky\right) \cdot \sin th \]
        2. metadata-evalN/A

          \[\leadsto \left(\sqrt{\frac{2}{1 - \cos \left(\color{blue}{\left(\mathsf{neg}\left(-2\right)\right)} \cdot kx\right)}} \cdot \sin ky\right) \cdot \sin th \]
        3. distribute-lft-neg-inN/A

          \[\leadsto \left(\sqrt{\frac{2}{1 - \cos \color{blue}{\left(\mathsf{neg}\left(-2 \cdot kx\right)\right)}}} \cdot \sin ky\right) \cdot \sin th \]
        4. lower--.f64N/A

          \[\leadsto \left(\sqrt{\frac{2}{\color{blue}{1 - \cos \left(\mathsf{neg}\left(-2 \cdot kx\right)\right)}}} \cdot \sin ky\right) \cdot \sin th \]
        5. cos-negN/A

          \[\leadsto \left(\sqrt{\frac{2}{1 - \color{blue}{\cos \left(-2 \cdot kx\right)}}} \cdot \sin ky\right) \cdot \sin th \]
        6. lower-cos.f64N/A

          \[\leadsto \left(\sqrt{\frac{2}{1 - \color{blue}{\cos \left(-2 \cdot kx\right)}}} \cdot \sin ky\right) \cdot \sin th \]
        7. *-commutativeN/A

          \[\leadsto \left(\sqrt{\frac{2}{1 - \cos \color{blue}{\left(kx \cdot -2\right)}}} \cdot \sin ky\right) \cdot \sin th \]
        8. lower-*.f6459.5

          \[\leadsto \left(\sqrt{\frac{2}{1 - \cos \color{blue}{\left(kx \cdot -2\right)}}} \cdot \sin ky\right) \cdot \sin th \]
      6. Simplified59.5%

        \[\leadsto \left(\sqrt{\color{blue}{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}} \cdot \sin ky\right) \cdot \sin th \]
    3. Recombined 2 regimes into one program.
    4. Final simplification79.0%

      \[\leadsto \begin{array}{l} \mathbf{if}\;{\sin kx}^{2} \leq 10^{-9}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \left(\sin ky \cdot \sqrt{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}\right)\\ \end{array} \]
    5. Add Preprocessing

    Alternative 24: 51.7% accurate, 1.1× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.002:\\ \;\;\;\;\frac{1}{\frac{\sqrt{\mathsf{fma}\left(-0.5, \cos \left(ky \cdot -2\right), \mathsf{fma}\left(kx, kx, 0.5\right)\right)}}{\sin ky \cdot th}}\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-152}:\\ \;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{elif}\;\sin ky \leq 0.0004:\\ \;\;\;\;\sin th \cdot \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \mathsf{fma}\left(0.008333333333333333, ky \cdot ky, -0.16666666666666666\right), ky\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
    (FPCore (kx ky th)
     :precision binary64
     (if (<= (sin ky) -0.002)
       (/
        1.0
        (/ (sqrt (fma -0.5 (cos (* ky -2.0)) (fma kx kx 0.5))) (* (sin ky) th)))
       (if (<= (sin ky) 5e-152)
         (* ky (/ (sin th) (sin kx)))
         (if (<= (sin ky) 0.0004)
           (*
            (sin th)
            (*
             (sqrt (/ 1.0 (fma (- 1.0 (cos (+ kx kx))) 0.5 (* ky ky))))
             (fma
              ky
              (*
               (* ky ky)
               (fma 0.008333333333333333 (* ky ky) -0.16666666666666666))
              ky)))
           (sin th)))))
    double code(double kx, double ky, double th) {
    	double tmp;
    	if (sin(ky) <= -0.002) {
    		tmp = 1.0 / (sqrt(fma(-0.5, cos((ky * -2.0)), fma(kx, kx, 0.5))) / (sin(ky) * th));
    	} else if (sin(ky) <= 5e-152) {
    		tmp = ky * (sin(th) / sin(kx));
    	} else if (sin(ky) <= 0.0004) {
    		tmp = sin(th) * (sqrt((1.0 / fma((1.0 - cos((kx + kx))), 0.5, (ky * ky)))) * fma(ky, ((ky * ky) * fma(0.008333333333333333, (ky * ky), -0.16666666666666666)), ky));
    	} else {
    		tmp = sin(th);
    	}
    	return tmp;
    }
    
    function code(kx, ky, th)
    	tmp = 0.0
    	if (sin(ky) <= -0.002)
    		tmp = Float64(1.0 / Float64(sqrt(fma(-0.5, cos(Float64(ky * -2.0)), fma(kx, kx, 0.5))) / Float64(sin(ky) * th)));
    	elseif (sin(ky) <= 5e-152)
    		tmp = Float64(ky * Float64(sin(th) / sin(kx)));
    	elseif (sin(ky) <= 0.0004)
    		tmp = Float64(sin(th) * Float64(sqrt(Float64(1.0 / fma(Float64(1.0 - cos(Float64(kx + kx))), 0.5, Float64(ky * ky)))) * fma(ky, Float64(Float64(ky * ky) * fma(0.008333333333333333, Float64(ky * ky), -0.16666666666666666)), ky)));
    	else
    		tmp = sin(th);
    	end
    	return tmp
    end
    
    code[kx_, ky_, th_] := If[LessEqual[N[Sin[ky], $MachinePrecision], -0.002], N[(1.0 / N[(N[Sqrt[N[(-0.5 * N[Cos[N[(ky * -2.0), $MachinePrecision]], $MachinePrecision] + N[(kx * kx + 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(N[Sin[ky], $MachinePrecision] * th), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 5e-152], N[(ky * N[(N[Sin[th], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 0.0004], N[(N[Sin[th], $MachinePrecision] * N[(N[Sqrt[N[(1.0 / N[(N[(1.0 - N[Cos[N[(kx + kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 0.5 + N[(ky * ky), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(ky * N[(N[(ky * ky), $MachinePrecision] * N[(0.008333333333333333 * N[(ky * ky), $MachinePrecision] + -0.16666666666666666), $MachinePrecision]), $MachinePrecision] + ky), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;\sin ky \leq -0.002:\\
    \;\;\;\;\frac{1}{\frac{\sqrt{\mathsf{fma}\left(-0.5, \cos \left(ky \cdot -2\right), \mathsf{fma}\left(kx, kx, 0.5\right)\right)}}{\sin ky \cdot th}}\\
    
    \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-152}:\\
    \;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\
    
    \mathbf{elif}\;\sin ky \leq 0.0004:\\
    \;\;\;\;\sin th \cdot \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \mathsf{fma}\left(0.008333333333333333, ky \cdot ky, -0.16666666666666666\right), ky\right)\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;\sin th\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 4 regimes
    2. if (sin.f64 ky) < -2e-3

      1. Initial program 99.7%

        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      2. Add Preprocessing
      3. Taylor expanded in kx around 0

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
      4. Step-by-step derivation
        1. unpow2N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
        2. lower-*.f6448.7

          \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
      5. Simplified48.7%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
      6. Applied egg-rr47.7%

        \[\leadsto \color{blue}{\frac{1}{\frac{\sqrt{\mathsf{fma}\left(kx, kx, \mathsf{fma}\left(\cos \left(ky + ky\right), -0.5, 0.5\right)\right)}}{\sin ky \cdot \sin th}}} \]
      7. Taylor expanded in th around 0

        \[\leadsto \frac{1}{\color{blue}{\frac{1}{th \cdot \sin ky} \cdot \sqrt{\frac{1}{2} + \left(\frac{-1}{2} \cdot \cos \left(2 \cdot ky\right) + {kx}^{2}\right)}}} \]
      8. Step-by-step derivation
        1. associate-*l/N/A

          \[\leadsto \frac{1}{\color{blue}{\frac{1 \cdot \sqrt{\frac{1}{2} + \left(\frac{-1}{2} \cdot \cos \left(2 \cdot ky\right) + {kx}^{2}\right)}}{th \cdot \sin ky}}} \]
        2. *-lft-identityN/A

          \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{\frac{1}{2} + \left(\frac{-1}{2} \cdot \cos \left(2 \cdot ky\right) + {kx}^{2}\right)}}}{th \cdot \sin ky}} \]
        3. lower-/.f64N/A

          \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{\frac{1}{2} + \left(\frac{-1}{2} \cdot \cos \left(2 \cdot ky\right) + {kx}^{2}\right)}}{th \cdot \sin ky}}} \]
        4. lower-sqrt.f64N/A

          \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{\frac{1}{2} + \left(\frac{-1}{2} \cdot \cos \left(2 \cdot ky\right) + {kx}^{2}\right)}}}{th \cdot \sin ky}} \]
        5. +-commutativeN/A

          \[\leadsto \frac{1}{\frac{\sqrt{\color{blue}{\left(\frac{-1}{2} \cdot \cos \left(2 \cdot ky\right) + {kx}^{2}\right) + \frac{1}{2}}}}{th \cdot \sin ky}} \]
        6. associate-+l+N/A

          \[\leadsto \frac{1}{\frac{\sqrt{\color{blue}{\frac{-1}{2} \cdot \cos \left(2 \cdot ky\right) + \left({kx}^{2} + \frac{1}{2}\right)}}}{th \cdot \sin ky}} \]
        7. lower-fma.f64N/A

          \[\leadsto \frac{1}{\frac{\sqrt{\color{blue}{\mathsf{fma}\left(\frac{-1}{2}, \cos \left(2 \cdot ky\right), {kx}^{2} + \frac{1}{2}\right)}}}{th \cdot \sin ky}} \]
        8. metadata-evalN/A

          \[\leadsto \frac{1}{\frac{\sqrt{\mathsf{fma}\left(\frac{-1}{2}, \cos \left(\color{blue}{\left(\mathsf{neg}\left(-2\right)\right)} \cdot ky\right), {kx}^{2} + \frac{1}{2}\right)}}{th \cdot \sin ky}} \]
        9. distribute-lft-neg-inN/A

          \[\leadsto \frac{1}{\frac{\sqrt{\mathsf{fma}\left(\frac{-1}{2}, \cos \color{blue}{\left(\mathsf{neg}\left(-2 \cdot ky\right)\right)}, {kx}^{2} + \frac{1}{2}\right)}}{th \cdot \sin ky}} \]
        10. cos-negN/A

          \[\leadsto \frac{1}{\frac{\sqrt{\mathsf{fma}\left(\frac{-1}{2}, \color{blue}{\cos \left(-2 \cdot ky\right)}, {kx}^{2} + \frac{1}{2}\right)}}{th \cdot \sin ky}} \]
        11. lower-cos.f64N/A

          \[\leadsto \frac{1}{\frac{\sqrt{\mathsf{fma}\left(\frac{-1}{2}, \color{blue}{\cos \left(-2 \cdot ky\right)}, {kx}^{2} + \frac{1}{2}\right)}}{th \cdot \sin ky}} \]
        12. *-commutativeN/A

          \[\leadsto \frac{1}{\frac{\sqrt{\mathsf{fma}\left(\frac{-1}{2}, \cos \color{blue}{\left(ky \cdot -2\right)}, {kx}^{2} + \frac{1}{2}\right)}}{th \cdot \sin ky}} \]
        13. lower-*.f64N/A

          \[\leadsto \frac{1}{\frac{\sqrt{\mathsf{fma}\left(\frac{-1}{2}, \cos \color{blue}{\left(ky \cdot -2\right)}, {kx}^{2} + \frac{1}{2}\right)}}{th \cdot \sin ky}} \]
        14. unpow2N/A

          \[\leadsto \frac{1}{\frac{\sqrt{\mathsf{fma}\left(\frac{-1}{2}, \cos \left(ky \cdot -2\right), \color{blue}{kx \cdot kx} + \frac{1}{2}\right)}}{th \cdot \sin ky}} \]
        15. lower-fma.f64N/A

          \[\leadsto \frac{1}{\frac{\sqrt{\mathsf{fma}\left(\frac{-1}{2}, \cos \left(ky \cdot -2\right), \color{blue}{\mathsf{fma}\left(kx, kx, \frac{1}{2}\right)}\right)}}{th \cdot \sin ky}} \]
        16. lower-*.f64N/A

          \[\leadsto \frac{1}{\frac{\sqrt{\mathsf{fma}\left(\frac{-1}{2}, \cos \left(ky \cdot -2\right), \mathsf{fma}\left(kx, kx, \frac{1}{2}\right)\right)}}{\color{blue}{th \cdot \sin ky}}} \]
        17. lower-sin.f6418.7

          \[\leadsto \frac{1}{\frac{\sqrt{\mathsf{fma}\left(-0.5, \cos \left(ky \cdot -2\right), \mathsf{fma}\left(kx, kx, 0.5\right)\right)}}{th \cdot \color{blue}{\sin ky}}} \]
      9. Simplified18.7%

        \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(-0.5, \cos \left(ky \cdot -2\right), \mathsf{fma}\left(kx, kx, 0.5\right)\right)}}{th \cdot \sin ky}}} \]

      if -2e-3 < (sin.f64 ky) < 4.9999999999999997e-152

      1. Initial program 89.4%

        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      2. Add Preprocessing
      3. Taylor expanded in ky around 0

        \[\leadsto \color{blue}{ky \cdot \left({ky}^{2} \cdot \left(\frac{-1}{2} \cdot \frac{\sin th}{{\sin kx}^{3}} + \frac{-1}{6} \cdot \frac{\sin th}{\sin kx}\right) + \frac{\sin th}{\sin kx}\right)} \]
      4. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto \color{blue}{ky \cdot \left({ky}^{2} \cdot \left(\frac{-1}{2} \cdot \frac{\sin th}{{\sin kx}^{3}} + \frac{-1}{6} \cdot \frac{\sin th}{\sin kx}\right) + \frac{\sin th}{\sin kx}\right)} \]
        2. distribute-lft-inN/A

          \[\leadsto ky \cdot \left(\color{blue}{\left({ky}^{2} \cdot \left(\frac{-1}{2} \cdot \frac{\sin th}{{\sin kx}^{3}}\right) + {ky}^{2} \cdot \left(\frac{-1}{6} \cdot \frac{\sin th}{\sin kx}\right)\right)} + \frac{\sin th}{\sin kx}\right) \]
        3. *-commutativeN/A

          \[\leadsto ky \cdot \left(\left(\color{blue}{\left(\frac{-1}{2} \cdot \frac{\sin th}{{\sin kx}^{3}}\right) \cdot {ky}^{2}} + {ky}^{2} \cdot \left(\frac{-1}{6} \cdot \frac{\sin th}{\sin kx}\right)\right) + \frac{\sin th}{\sin kx}\right) \]
        4. associate-+r+N/A

          \[\leadsto ky \cdot \color{blue}{\left(\left(\frac{-1}{2} \cdot \frac{\sin th}{{\sin kx}^{3}}\right) \cdot {ky}^{2} + \left({ky}^{2} \cdot \left(\frac{-1}{6} \cdot \frac{\sin th}{\sin kx}\right) + \frac{\sin th}{\sin kx}\right)\right)} \]
        5. +-commutativeN/A

          \[\leadsto ky \cdot \color{blue}{\left(\left({ky}^{2} \cdot \left(\frac{-1}{6} \cdot \frac{\sin th}{\sin kx}\right) + \frac{\sin th}{\sin kx}\right) + \left(\frac{-1}{2} \cdot \frac{\sin th}{{\sin kx}^{3}}\right) \cdot {ky}^{2}\right)} \]
      5. Simplified50.9%

        \[\leadsto \color{blue}{ky \cdot \mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right), \frac{\sin th}{\sin kx}, \frac{\left(ky \cdot ky\right) \cdot \left(-0.5 \cdot \sin th\right)}{{\sin kx}^{3}}\right)} \]
      6. Taylor expanded in ky around 0

        \[\leadsto ky \cdot \color{blue}{\frac{\sin th}{\sin kx}} \]
      7. Step-by-step derivation
        1. lower-/.f64N/A

          \[\leadsto ky \cdot \color{blue}{\frac{\sin th}{\sin kx}} \]
        2. lower-sin.f64N/A

          \[\leadsto ky \cdot \frac{\color{blue}{\sin th}}{\sin kx} \]
        3. lower-sin.f6456.7

          \[\leadsto ky \cdot \frac{\sin th}{\color{blue}{\sin kx}} \]
      8. Simplified56.7%

        \[\leadsto ky \cdot \color{blue}{\frac{\sin th}{\sin kx}} \]

      if 4.9999999999999997e-152 < (sin.f64 ky) < 4.00000000000000019e-4

      1. Initial program 99.5%

        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      2. Add Preprocessing
      3. Applied egg-rr62.3%

        \[\leadsto \color{blue}{\left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, 0.5 + -0.5 \cdot \cos \left(ky + ky\right)\right)}} \cdot \sin ky\right)} \cdot \sin th \]
      4. Taylor expanded in ky around 0

        \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, \color{blue}{{ky}^{2}}\right)}} \cdot \sin ky\right) \cdot \sin th \]
      5. Step-by-step derivation
        1. unpow2N/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, \color{blue}{ky \cdot ky}\right)}} \cdot \sin ky\right) \cdot \sin th \]
        2. lower-*.f6488.5

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, \color{blue}{ky \cdot ky}\right)}} \cdot \sin ky\right) \cdot \sin th \]
      6. Simplified88.5%

        \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, \color{blue}{ky \cdot ky}\right)}} \cdot \sin ky\right) \cdot \sin th \]
      7. Taylor expanded in ky around 0

        \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \color{blue}{\left(ky \cdot \left(1 + {ky}^{2} \cdot \left(\frac{1}{120} \cdot {ky}^{2} - \frac{1}{6}\right)\right)\right)}\right) \cdot \sin th \]
      8. Step-by-step derivation
        1. +-commutativeN/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \left(ky \cdot \color{blue}{\left({ky}^{2} \cdot \left(\frac{1}{120} \cdot {ky}^{2} - \frac{1}{6}\right) + 1\right)}\right)\right) \cdot \sin th \]
        2. distribute-lft-inN/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \color{blue}{\left(ky \cdot \left({ky}^{2} \cdot \left(\frac{1}{120} \cdot {ky}^{2} - \frac{1}{6}\right)\right) + ky \cdot 1\right)}\right) \cdot \sin th \]
        3. *-rgt-identityN/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \left(ky \cdot \left({ky}^{2} \cdot \left(\frac{1}{120} \cdot {ky}^{2} - \frac{1}{6}\right)\right) + \color{blue}{ky}\right)\right) \cdot \sin th \]
        4. lower-fma.f64N/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \color{blue}{\mathsf{fma}\left(ky, {ky}^{2} \cdot \left(\frac{1}{120} \cdot {ky}^{2} - \frac{1}{6}\right), ky\right)}\right) \cdot \sin th \]
        5. lower-*.f64N/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \color{blue}{{ky}^{2} \cdot \left(\frac{1}{120} \cdot {ky}^{2} - \frac{1}{6}\right)}, ky\right)\right) \cdot \sin th \]
        6. unpow2N/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \color{blue}{\left(ky \cdot ky\right)} \cdot \left(\frac{1}{120} \cdot {ky}^{2} - \frac{1}{6}\right), ky\right)\right) \cdot \sin th \]
        7. lower-*.f64N/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \color{blue}{\left(ky \cdot ky\right)} \cdot \left(\frac{1}{120} \cdot {ky}^{2} - \frac{1}{6}\right), ky\right)\right) \cdot \sin th \]
        8. sub-negN/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \color{blue}{\left(\frac{1}{120} \cdot {ky}^{2} + \left(\mathsf{neg}\left(\frac{1}{6}\right)\right)\right)}, ky\right)\right) \cdot \sin th \]
        9. metadata-evalN/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \left(\frac{1}{120} \cdot {ky}^{2} + \color{blue}{\frac{-1}{6}}\right), ky\right)\right) \cdot \sin th \]
        10. lower-fma.f64N/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \color{blue}{\mathsf{fma}\left(\frac{1}{120}, {ky}^{2}, \frac{-1}{6}\right)}, ky\right)\right) \cdot \sin th \]
        11. unpow2N/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \mathsf{fma}\left(\frac{1}{120}, \color{blue}{ky \cdot ky}, \frac{-1}{6}\right), ky\right)\right) \cdot \sin th \]
        12. lower-*.f6488.5

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \mathsf{fma}\left(0.008333333333333333, \color{blue}{ky \cdot ky}, -0.16666666666666666\right), ky\right)\right) \cdot \sin th \]
      9. Simplified88.5%

        \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, ky \cdot ky\right)}} \cdot \color{blue}{\mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \mathsf{fma}\left(0.008333333333333333, ky \cdot ky, -0.16666666666666666\right), ky\right)}\right) \cdot \sin th \]

      if 4.00000000000000019e-4 < (sin.f64 ky)

      1. Initial program 99.7%

        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      2. Add Preprocessing
      3. Taylor expanded in kx around 0

        \[\leadsto \color{blue}{\sin th} \]
      4. Step-by-step derivation
        1. lower-sin.f6465.8

          \[\leadsto \color{blue}{\sin th} \]
      5. Simplified65.8%

        \[\leadsto \color{blue}{\sin th} \]
    3. Recombined 4 regimes into one program.
    4. Final simplification54.4%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.002:\\ \;\;\;\;\frac{1}{\frac{\sqrt{\mathsf{fma}\left(-0.5, \cos \left(ky \cdot -2\right), \mathsf{fma}\left(kx, kx, 0.5\right)\right)}}{\sin ky \cdot th}}\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-152}:\\ \;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{elif}\;\sin ky \leq 0.0004:\\ \;\;\;\;\sin th \cdot \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \mathsf{fma}\left(0.008333333333333333, ky \cdot ky, -0.16666666666666666\right), ky\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
    5. Add Preprocessing

    Alternative 25: 51.7% accurate, 1.1× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.002:\\ \;\;\;\;\frac{1}{\frac{\sqrt{\mathsf{fma}\left(-0.5, \cos \left(ky \cdot -2\right), \mathsf{fma}\left(kx, kx, 0.5\right)\right)}}{\sin ky \cdot th}}\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-152}:\\ \;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{elif}\;\sin ky \leq 0.0004:\\ \;\;\;\;\sin th \cdot \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, -0.16666666666666666 \cdot \left(ky \cdot ky\right), ky\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
    (FPCore (kx ky th)
     :precision binary64
     (if (<= (sin ky) -0.002)
       (/
        1.0
        (/ (sqrt (fma -0.5 (cos (* ky -2.0)) (fma kx kx 0.5))) (* (sin ky) th)))
       (if (<= (sin ky) 5e-152)
         (* ky (/ (sin th) (sin kx)))
         (if (<= (sin ky) 0.0004)
           (*
            (sin th)
            (*
             (sqrt (/ 1.0 (fma (- 1.0 (cos (+ kx kx))) 0.5 (* ky ky))))
             (fma ky (* -0.16666666666666666 (* ky ky)) ky)))
           (sin th)))))
    double code(double kx, double ky, double th) {
    	double tmp;
    	if (sin(ky) <= -0.002) {
    		tmp = 1.0 / (sqrt(fma(-0.5, cos((ky * -2.0)), fma(kx, kx, 0.5))) / (sin(ky) * th));
    	} else if (sin(ky) <= 5e-152) {
    		tmp = ky * (sin(th) / sin(kx));
    	} else if (sin(ky) <= 0.0004) {
    		tmp = sin(th) * (sqrt((1.0 / fma((1.0 - cos((kx + kx))), 0.5, (ky * ky)))) * fma(ky, (-0.16666666666666666 * (ky * ky)), ky));
    	} else {
    		tmp = sin(th);
    	}
    	return tmp;
    }
    
    function code(kx, ky, th)
    	tmp = 0.0
    	if (sin(ky) <= -0.002)
    		tmp = Float64(1.0 / Float64(sqrt(fma(-0.5, cos(Float64(ky * -2.0)), fma(kx, kx, 0.5))) / Float64(sin(ky) * th)));
    	elseif (sin(ky) <= 5e-152)
    		tmp = Float64(ky * Float64(sin(th) / sin(kx)));
    	elseif (sin(ky) <= 0.0004)
    		tmp = Float64(sin(th) * Float64(sqrt(Float64(1.0 / fma(Float64(1.0 - cos(Float64(kx + kx))), 0.5, Float64(ky * ky)))) * fma(ky, Float64(-0.16666666666666666 * Float64(ky * ky)), ky)));
    	else
    		tmp = sin(th);
    	end
    	return tmp
    end
    
    code[kx_, ky_, th_] := If[LessEqual[N[Sin[ky], $MachinePrecision], -0.002], N[(1.0 / N[(N[Sqrt[N[(-0.5 * N[Cos[N[(ky * -2.0), $MachinePrecision]], $MachinePrecision] + N[(kx * kx + 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(N[Sin[ky], $MachinePrecision] * th), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 5e-152], N[(ky * N[(N[Sin[th], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 0.0004], N[(N[Sin[th], $MachinePrecision] * N[(N[Sqrt[N[(1.0 / N[(N[(1.0 - N[Cos[N[(kx + kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 0.5 + N[(ky * ky), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(ky * N[(-0.16666666666666666 * N[(ky * ky), $MachinePrecision]), $MachinePrecision] + ky), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;\sin ky \leq -0.002:\\
    \;\;\;\;\frac{1}{\frac{\sqrt{\mathsf{fma}\left(-0.5, \cos \left(ky \cdot -2\right), \mathsf{fma}\left(kx, kx, 0.5\right)\right)}}{\sin ky \cdot th}}\\
    
    \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-152}:\\
    \;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\
    
    \mathbf{elif}\;\sin ky \leq 0.0004:\\
    \;\;\;\;\sin th \cdot \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, -0.16666666666666666 \cdot \left(ky \cdot ky\right), ky\right)\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;\sin th\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 4 regimes
    2. if (sin.f64 ky) < -2e-3

      1. Initial program 99.7%

        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      2. Add Preprocessing
      3. Taylor expanded in kx around 0

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
      4. Step-by-step derivation
        1. unpow2N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
        2. lower-*.f6448.7

          \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
      5. Simplified48.7%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
      6. Applied egg-rr47.7%

        \[\leadsto \color{blue}{\frac{1}{\frac{\sqrt{\mathsf{fma}\left(kx, kx, \mathsf{fma}\left(\cos \left(ky + ky\right), -0.5, 0.5\right)\right)}}{\sin ky \cdot \sin th}}} \]
      7. Taylor expanded in th around 0

        \[\leadsto \frac{1}{\color{blue}{\frac{1}{th \cdot \sin ky} \cdot \sqrt{\frac{1}{2} + \left(\frac{-1}{2} \cdot \cos \left(2 \cdot ky\right) + {kx}^{2}\right)}}} \]
      8. Step-by-step derivation
        1. associate-*l/N/A

          \[\leadsto \frac{1}{\color{blue}{\frac{1 \cdot \sqrt{\frac{1}{2} + \left(\frac{-1}{2} \cdot \cos \left(2 \cdot ky\right) + {kx}^{2}\right)}}{th \cdot \sin ky}}} \]
        2. *-lft-identityN/A

          \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{\frac{1}{2} + \left(\frac{-1}{2} \cdot \cos \left(2 \cdot ky\right) + {kx}^{2}\right)}}}{th \cdot \sin ky}} \]
        3. lower-/.f64N/A

          \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{\frac{1}{2} + \left(\frac{-1}{2} \cdot \cos \left(2 \cdot ky\right) + {kx}^{2}\right)}}{th \cdot \sin ky}}} \]
        4. lower-sqrt.f64N/A

          \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{\frac{1}{2} + \left(\frac{-1}{2} \cdot \cos \left(2 \cdot ky\right) + {kx}^{2}\right)}}}{th \cdot \sin ky}} \]
        5. +-commutativeN/A

          \[\leadsto \frac{1}{\frac{\sqrt{\color{blue}{\left(\frac{-1}{2} \cdot \cos \left(2 \cdot ky\right) + {kx}^{2}\right) + \frac{1}{2}}}}{th \cdot \sin ky}} \]
        6. associate-+l+N/A

          \[\leadsto \frac{1}{\frac{\sqrt{\color{blue}{\frac{-1}{2} \cdot \cos \left(2 \cdot ky\right) + \left({kx}^{2} + \frac{1}{2}\right)}}}{th \cdot \sin ky}} \]
        7. lower-fma.f64N/A

          \[\leadsto \frac{1}{\frac{\sqrt{\color{blue}{\mathsf{fma}\left(\frac{-1}{2}, \cos \left(2 \cdot ky\right), {kx}^{2} + \frac{1}{2}\right)}}}{th \cdot \sin ky}} \]
        8. metadata-evalN/A

          \[\leadsto \frac{1}{\frac{\sqrt{\mathsf{fma}\left(\frac{-1}{2}, \cos \left(\color{blue}{\left(\mathsf{neg}\left(-2\right)\right)} \cdot ky\right), {kx}^{2} + \frac{1}{2}\right)}}{th \cdot \sin ky}} \]
        9. distribute-lft-neg-inN/A

          \[\leadsto \frac{1}{\frac{\sqrt{\mathsf{fma}\left(\frac{-1}{2}, \cos \color{blue}{\left(\mathsf{neg}\left(-2 \cdot ky\right)\right)}, {kx}^{2} + \frac{1}{2}\right)}}{th \cdot \sin ky}} \]
        10. cos-negN/A

          \[\leadsto \frac{1}{\frac{\sqrt{\mathsf{fma}\left(\frac{-1}{2}, \color{blue}{\cos \left(-2 \cdot ky\right)}, {kx}^{2} + \frac{1}{2}\right)}}{th \cdot \sin ky}} \]
        11. lower-cos.f64N/A

          \[\leadsto \frac{1}{\frac{\sqrt{\mathsf{fma}\left(\frac{-1}{2}, \color{blue}{\cos \left(-2 \cdot ky\right)}, {kx}^{2} + \frac{1}{2}\right)}}{th \cdot \sin ky}} \]
        12. *-commutativeN/A

          \[\leadsto \frac{1}{\frac{\sqrt{\mathsf{fma}\left(\frac{-1}{2}, \cos \color{blue}{\left(ky \cdot -2\right)}, {kx}^{2} + \frac{1}{2}\right)}}{th \cdot \sin ky}} \]
        13. lower-*.f64N/A

          \[\leadsto \frac{1}{\frac{\sqrt{\mathsf{fma}\left(\frac{-1}{2}, \cos \color{blue}{\left(ky \cdot -2\right)}, {kx}^{2} + \frac{1}{2}\right)}}{th \cdot \sin ky}} \]
        14. unpow2N/A

          \[\leadsto \frac{1}{\frac{\sqrt{\mathsf{fma}\left(\frac{-1}{2}, \cos \left(ky \cdot -2\right), \color{blue}{kx \cdot kx} + \frac{1}{2}\right)}}{th \cdot \sin ky}} \]
        15. lower-fma.f64N/A

          \[\leadsto \frac{1}{\frac{\sqrt{\mathsf{fma}\left(\frac{-1}{2}, \cos \left(ky \cdot -2\right), \color{blue}{\mathsf{fma}\left(kx, kx, \frac{1}{2}\right)}\right)}}{th \cdot \sin ky}} \]
        16. lower-*.f64N/A

          \[\leadsto \frac{1}{\frac{\sqrt{\mathsf{fma}\left(\frac{-1}{2}, \cos \left(ky \cdot -2\right), \mathsf{fma}\left(kx, kx, \frac{1}{2}\right)\right)}}{\color{blue}{th \cdot \sin ky}}} \]
        17. lower-sin.f6418.7

          \[\leadsto \frac{1}{\frac{\sqrt{\mathsf{fma}\left(-0.5, \cos \left(ky \cdot -2\right), \mathsf{fma}\left(kx, kx, 0.5\right)\right)}}{th \cdot \color{blue}{\sin ky}}} \]
      9. Simplified18.7%

        \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(-0.5, \cos \left(ky \cdot -2\right), \mathsf{fma}\left(kx, kx, 0.5\right)\right)}}{th \cdot \sin ky}}} \]

      if -2e-3 < (sin.f64 ky) < 4.9999999999999997e-152

      1. Initial program 89.4%

        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      2. Add Preprocessing
      3. Taylor expanded in ky around 0

        \[\leadsto \color{blue}{ky \cdot \left({ky}^{2} \cdot \left(\frac{-1}{2} \cdot \frac{\sin th}{{\sin kx}^{3}} + \frac{-1}{6} \cdot \frac{\sin th}{\sin kx}\right) + \frac{\sin th}{\sin kx}\right)} \]
      4. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto \color{blue}{ky \cdot \left({ky}^{2} \cdot \left(\frac{-1}{2} \cdot \frac{\sin th}{{\sin kx}^{3}} + \frac{-1}{6} \cdot \frac{\sin th}{\sin kx}\right) + \frac{\sin th}{\sin kx}\right)} \]
        2. distribute-lft-inN/A

          \[\leadsto ky \cdot \left(\color{blue}{\left({ky}^{2} \cdot \left(\frac{-1}{2} \cdot \frac{\sin th}{{\sin kx}^{3}}\right) + {ky}^{2} \cdot \left(\frac{-1}{6} \cdot \frac{\sin th}{\sin kx}\right)\right)} + \frac{\sin th}{\sin kx}\right) \]
        3. *-commutativeN/A

          \[\leadsto ky \cdot \left(\left(\color{blue}{\left(\frac{-1}{2} \cdot \frac{\sin th}{{\sin kx}^{3}}\right) \cdot {ky}^{2}} + {ky}^{2} \cdot \left(\frac{-1}{6} \cdot \frac{\sin th}{\sin kx}\right)\right) + \frac{\sin th}{\sin kx}\right) \]
        4. associate-+r+N/A

          \[\leadsto ky \cdot \color{blue}{\left(\left(\frac{-1}{2} \cdot \frac{\sin th}{{\sin kx}^{3}}\right) \cdot {ky}^{2} + \left({ky}^{2} \cdot \left(\frac{-1}{6} \cdot \frac{\sin th}{\sin kx}\right) + \frac{\sin th}{\sin kx}\right)\right)} \]
        5. +-commutativeN/A

          \[\leadsto ky \cdot \color{blue}{\left(\left({ky}^{2} \cdot \left(\frac{-1}{6} \cdot \frac{\sin th}{\sin kx}\right) + \frac{\sin th}{\sin kx}\right) + \left(\frac{-1}{2} \cdot \frac{\sin th}{{\sin kx}^{3}}\right) \cdot {ky}^{2}\right)} \]
      5. Simplified50.9%

        \[\leadsto \color{blue}{ky \cdot \mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right), \frac{\sin th}{\sin kx}, \frac{\left(ky \cdot ky\right) \cdot \left(-0.5 \cdot \sin th\right)}{{\sin kx}^{3}}\right)} \]
      6. Taylor expanded in ky around 0

        \[\leadsto ky \cdot \color{blue}{\frac{\sin th}{\sin kx}} \]
      7. Step-by-step derivation
        1. lower-/.f64N/A

          \[\leadsto ky \cdot \color{blue}{\frac{\sin th}{\sin kx}} \]
        2. lower-sin.f64N/A

          \[\leadsto ky \cdot \frac{\color{blue}{\sin th}}{\sin kx} \]
        3. lower-sin.f6456.7

          \[\leadsto ky \cdot \frac{\sin th}{\color{blue}{\sin kx}} \]
      8. Simplified56.7%

        \[\leadsto ky \cdot \color{blue}{\frac{\sin th}{\sin kx}} \]

      if 4.9999999999999997e-152 < (sin.f64 ky) < 4.00000000000000019e-4

      1. Initial program 99.5%

        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      2. Add Preprocessing
      3. Applied egg-rr62.3%

        \[\leadsto \color{blue}{\left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, 0.5 + -0.5 \cdot \cos \left(ky + ky\right)\right)}} \cdot \sin ky\right)} \cdot \sin th \]
      4. Taylor expanded in ky around 0

        \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, \color{blue}{{ky}^{2}}\right)}} \cdot \sin ky\right) \cdot \sin th \]
      5. Step-by-step derivation
        1. unpow2N/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, \color{blue}{ky \cdot ky}\right)}} \cdot \sin ky\right) \cdot \sin th \]
        2. lower-*.f6488.5

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, \color{blue}{ky \cdot ky}\right)}} \cdot \sin ky\right) \cdot \sin th \]
      6. Simplified88.5%

        \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, \color{blue}{ky \cdot ky}\right)}} \cdot \sin ky\right) \cdot \sin th \]
      7. Taylor expanded in ky around 0

        \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \color{blue}{\left(ky \cdot \left(1 + \frac{-1}{6} \cdot {ky}^{2}\right)\right)}\right) \cdot \sin th \]
      8. Step-by-step derivation
        1. +-commutativeN/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \left(ky \cdot \color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)}\right)\right) \cdot \sin th \]
        2. distribute-lft-inN/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \color{blue}{\left(ky \cdot \left(\frac{-1}{6} \cdot {ky}^{2}\right) + ky \cdot 1\right)}\right) \cdot \sin th \]
        3. *-rgt-identityN/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \left(ky \cdot \left(\frac{-1}{6} \cdot {ky}^{2}\right) + \color{blue}{ky}\right)\right) \cdot \sin th \]
        4. lower-fma.f64N/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \color{blue}{\mathsf{fma}\left(ky, \frac{-1}{6} \cdot {ky}^{2}, ky\right)}\right) \cdot \sin th \]
        5. lower-*.f64N/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \color{blue}{\frac{-1}{6} \cdot {ky}^{2}}, ky\right)\right) \cdot \sin th \]
        6. unpow2N/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \frac{-1}{6} \cdot \color{blue}{\left(ky \cdot ky\right)}, ky\right)\right) \cdot \sin th \]
        7. lower-*.f6488.5

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, -0.16666666666666666 \cdot \color{blue}{\left(ky \cdot ky\right)}, ky\right)\right) \cdot \sin th \]
      9. Simplified88.5%

        \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, ky \cdot ky\right)}} \cdot \color{blue}{\mathsf{fma}\left(ky, -0.16666666666666666 \cdot \left(ky \cdot ky\right), ky\right)}\right) \cdot \sin th \]

      if 4.00000000000000019e-4 < (sin.f64 ky)

      1. Initial program 99.7%

        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      2. Add Preprocessing
      3. Taylor expanded in kx around 0

        \[\leadsto \color{blue}{\sin th} \]
      4. Step-by-step derivation
        1. lower-sin.f6465.8

          \[\leadsto \color{blue}{\sin th} \]
      5. Simplified65.8%

        \[\leadsto \color{blue}{\sin th} \]
    3. Recombined 4 regimes into one program.
    4. Final simplification54.4%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.002:\\ \;\;\;\;\frac{1}{\frac{\sqrt{\mathsf{fma}\left(-0.5, \cos \left(ky \cdot -2\right), \mathsf{fma}\left(kx, kx, 0.5\right)\right)}}{\sin ky \cdot th}}\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-152}:\\ \;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{elif}\;\sin ky \leq 0.0004:\\ \;\;\;\;\sin th \cdot \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, -0.16666666666666666 \cdot \left(ky \cdot ky\right), ky\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
    5. Add Preprocessing

    Alternative 26: 46.4% accurate, 1.3× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq 5 \cdot 10^{-152}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\ \mathbf{elif}\;\sin ky \leq 0.0004:\\ \;\;\;\;\sin th \cdot \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \mathsf{fma}\left(0.008333333333333333, ky \cdot ky, -0.16666666666666666\right), ky\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
    (FPCore (kx ky th)
     :precision binary64
     (if (<= (sin ky) 5e-152)
       (* (sin th) (/ (sin ky) (sin kx)))
       (if (<= (sin ky) 0.0004)
         (*
          (sin th)
          (*
           (sqrt (/ 1.0 (fma (- 1.0 (cos (+ kx kx))) 0.5 (* ky ky))))
           (fma
            ky
            (* (* ky ky) (fma 0.008333333333333333 (* ky ky) -0.16666666666666666))
            ky)))
         (sin th))))
    double code(double kx, double ky, double th) {
    	double tmp;
    	if (sin(ky) <= 5e-152) {
    		tmp = sin(th) * (sin(ky) / sin(kx));
    	} else if (sin(ky) <= 0.0004) {
    		tmp = sin(th) * (sqrt((1.0 / fma((1.0 - cos((kx + kx))), 0.5, (ky * ky)))) * fma(ky, ((ky * ky) * fma(0.008333333333333333, (ky * ky), -0.16666666666666666)), ky));
    	} else {
    		tmp = sin(th);
    	}
    	return tmp;
    }
    
    function code(kx, ky, th)
    	tmp = 0.0
    	if (sin(ky) <= 5e-152)
    		tmp = Float64(sin(th) * Float64(sin(ky) / sin(kx)));
    	elseif (sin(ky) <= 0.0004)
    		tmp = Float64(sin(th) * Float64(sqrt(Float64(1.0 / fma(Float64(1.0 - cos(Float64(kx + kx))), 0.5, Float64(ky * ky)))) * fma(ky, Float64(Float64(ky * ky) * fma(0.008333333333333333, Float64(ky * ky), -0.16666666666666666)), ky)));
    	else
    		tmp = sin(th);
    	end
    	return tmp
    end
    
    code[kx_, ky_, th_] := If[LessEqual[N[Sin[ky], $MachinePrecision], 5e-152], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 0.0004], N[(N[Sin[th], $MachinePrecision] * N[(N[Sqrt[N[(1.0 / N[(N[(1.0 - N[Cos[N[(kx + kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 0.5 + N[(ky * ky), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(ky * N[(N[(ky * ky), $MachinePrecision] * N[(0.008333333333333333 * N[(ky * ky), $MachinePrecision] + -0.16666666666666666), $MachinePrecision]), $MachinePrecision] + ky), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;\sin ky \leq 5 \cdot 10^{-152}:\\
    \;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\
    
    \mathbf{elif}\;\sin ky \leq 0.0004:\\
    \;\;\;\;\sin th \cdot \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \mathsf{fma}\left(0.008333333333333333, ky \cdot ky, -0.16666666666666666\right), ky\right)\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;\sin th\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if (sin.f64 ky) < 4.9999999999999997e-152

      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 ky around 0

        \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
      4. Step-by-step derivation
        1. lower-sin.f6436.6

          \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
      5. Simplified36.6%

        \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]

      if 4.9999999999999997e-152 < (sin.f64 ky) < 4.00000000000000019e-4

      1. Initial program 99.5%

        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      2. Add Preprocessing
      3. Applied egg-rr62.3%

        \[\leadsto \color{blue}{\left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, 0.5 + -0.5 \cdot \cos \left(ky + ky\right)\right)}} \cdot \sin ky\right)} \cdot \sin th \]
      4. Taylor expanded in ky around 0

        \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, \color{blue}{{ky}^{2}}\right)}} \cdot \sin ky\right) \cdot \sin th \]
      5. Step-by-step derivation
        1. unpow2N/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, \color{blue}{ky \cdot ky}\right)}} \cdot \sin ky\right) \cdot \sin th \]
        2. lower-*.f6488.5

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, \color{blue}{ky \cdot ky}\right)}} \cdot \sin ky\right) \cdot \sin th \]
      6. Simplified88.5%

        \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, \color{blue}{ky \cdot ky}\right)}} \cdot \sin ky\right) \cdot \sin th \]
      7. Taylor expanded in ky around 0

        \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \color{blue}{\left(ky \cdot \left(1 + {ky}^{2} \cdot \left(\frac{1}{120} \cdot {ky}^{2} - \frac{1}{6}\right)\right)\right)}\right) \cdot \sin th \]
      8. Step-by-step derivation
        1. +-commutativeN/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \left(ky \cdot \color{blue}{\left({ky}^{2} \cdot \left(\frac{1}{120} \cdot {ky}^{2} - \frac{1}{6}\right) + 1\right)}\right)\right) \cdot \sin th \]
        2. distribute-lft-inN/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \color{blue}{\left(ky \cdot \left({ky}^{2} \cdot \left(\frac{1}{120} \cdot {ky}^{2} - \frac{1}{6}\right)\right) + ky \cdot 1\right)}\right) \cdot \sin th \]
        3. *-rgt-identityN/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \left(ky \cdot \left({ky}^{2} \cdot \left(\frac{1}{120} \cdot {ky}^{2} - \frac{1}{6}\right)\right) + \color{blue}{ky}\right)\right) \cdot \sin th \]
        4. lower-fma.f64N/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \color{blue}{\mathsf{fma}\left(ky, {ky}^{2} \cdot \left(\frac{1}{120} \cdot {ky}^{2} - \frac{1}{6}\right), ky\right)}\right) \cdot \sin th \]
        5. lower-*.f64N/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \color{blue}{{ky}^{2} \cdot \left(\frac{1}{120} \cdot {ky}^{2} - \frac{1}{6}\right)}, ky\right)\right) \cdot \sin th \]
        6. unpow2N/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \color{blue}{\left(ky \cdot ky\right)} \cdot \left(\frac{1}{120} \cdot {ky}^{2} - \frac{1}{6}\right), ky\right)\right) \cdot \sin th \]
        7. lower-*.f64N/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \color{blue}{\left(ky \cdot ky\right)} \cdot \left(\frac{1}{120} \cdot {ky}^{2} - \frac{1}{6}\right), ky\right)\right) \cdot \sin th \]
        8. sub-negN/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \color{blue}{\left(\frac{1}{120} \cdot {ky}^{2} + \left(\mathsf{neg}\left(\frac{1}{6}\right)\right)\right)}, ky\right)\right) \cdot \sin th \]
        9. metadata-evalN/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \left(\frac{1}{120} \cdot {ky}^{2} + \color{blue}{\frac{-1}{6}}\right), ky\right)\right) \cdot \sin th \]
        10. lower-fma.f64N/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \color{blue}{\mathsf{fma}\left(\frac{1}{120}, {ky}^{2}, \frac{-1}{6}\right)}, ky\right)\right) \cdot \sin th \]
        11. unpow2N/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \mathsf{fma}\left(\frac{1}{120}, \color{blue}{ky \cdot ky}, \frac{-1}{6}\right), ky\right)\right) \cdot \sin th \]
        12. lower-*.f6488.5

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \mathsf{fma}\left(0.008333333333333333, \color{blue}{ky \cdot ky}, -0.16666666666666666\right), ky\right)\right) \cdot \sin th \]
      9. Simplified88.5%

        \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, ky \cdot ky\right)}} \cdot \color{blue}{\mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \mathsf{fma}\left(0.008333333333333333, ky \cdot ky, -0.16666666666666666\right), ky\right)}\right) \cdot \sin th \]

      if 4.00000000000000019e-4 < (sin.f64 ky)

      1. Initial program 99.7%

        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      2. Add Preprocessing
      3. Taylor expanded in kx around 0

        \[\leadsto \color{blue}{\sin th} \]
      4. Step-by-step derivation
        1. lower-sin.f6465.8

          \[\leadsto \color{blue}{\sin th} \]
      5. Simplified65.8%

        \[\leadsto \color{blue}{\sin th} \]
    3. Recombined 3 regimes into one program.
    4. Final simplification51.9%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq 5 \cdot 10^{-152}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\ \mathbf{elif}\;\sin ky \leq 0.0004:\\ \;\;\;\;\sin th \cdot \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \mathsf{fma}\left(0.008333333333333333, ky \cdot ky, -0.16666666666666666\right), ky\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
    5. Add Preprocessing

    Alternative 27: 43.6% accurate, 1.6× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;kx \leq 1.22 \cdot 10^{-162}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;kx \leq 0.5:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \left(kx \cdot kx\right) \cdot \mathsf{fma}\left(kx \cdot kx, \mathsf{fma}\left(kx \cdot kx, \mathsf{fma}\left(kx \cdot kx, -0.0031746031746031746, 0.044444444444444446\right), -0.3333333333333333\right), 1\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \left(\sin ky \cdot \sqrt{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}\right)\\ \end{array} \end{array} \]
    (FPCore (kx ky th)
     :precision binary64
     (if (<= kx 1.22e-162)
       (sin th)
       (if (<= kx 0.5)
         (*
          (sin th)
          (/
           (sin ky)
           (sqrt
            (fma
             (- 1.0 (cos (+ ky ky)))
             0.5
             (*
              (* kx kx)
              (fma
               (* kx kx)
               (fma
                (* kx kx)
                (fma (* kx kx) -0.0031746031746031746 0.044444444444444446)
                -0.3333333333333333)
               1.0))))))
         (* (sin th) (* (sin ky) (sqrt (/ 2.0 (- 1.0 (cos (* kx -2.0))))))))))
    double code(double kx, double ky, double th) {
    	double tmp;
    	if (kx <= 1.22e-162) {
    		tmp = sin(th);
    	} else if (kx <= 0.5) {
    		tmp = sin(th) * (sin(ky) / sqrt(fma((1.0 - cos((ky + ky))), 0.5, ((kx * kx) * fma((kx * kx), fma((kx * kx), fma((kx * kx), -0.0031746031746031746, 0.044444444444444446), -0.3333333333333333), 1.0)))));
    	} else {
    		tmp = sin(th) * (sin(ky) * sqrt((2.0 / (1.0 - cos((kx * -2.0))))));
    	}
    	return tmp;
    }
    
    function code(kx, ky, th)
    	tmp = 0.0
    	if (kx <= 1.22e-162)
    		tmp = sin(th);
    	elseif (kx <= 0.5)
    		tmp = Float64(sin(th) * Float64(sin(ky) / sqrt(fma(Float64(1.0 - cos(Float64(ky + ky))), 0.5, Float64(Float64(kx * kx) * fma(Float64(kx * kx), fma(Float64(kx * kx), fma(Float64(kx * kx), -0.0031746031746031746, 0.044444444444444446), -0.3333333333333333), 1.0))))));
    	else
    		tmp = Float64(sin(th) * Float64(sin(ky) * sqrt(Float64(2.0 / Float64(1.0 - cos(Float64(kx * -2.0)))))));
    	end
    	return tmp
    end
    
    code[kx_, ky_, th_] := If[LessEqual[kx, 1.22e-162], N[Sin[th], $MachinePrecision], If[LessEqual[kx, 0.5], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(1.0 - N[Cos[N[(ky + ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 0.5 + N[(N[(kx * kx), $MachinePrecision] * N[(N[(kx * kx), $MachinePrecision] * N[(N[(kx * kx), $MachinePrecision] * N[(N[(kx * kx), $MachinePrecision] * -0.0031746031746031746 + 0.044444444444444446), $MachinePrecision] + -0.3333333333333333), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] * N[Sqrt[N[(2.0 / N[(1.0 - N[Cos[N[(kx * -2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;kx \leq 1.22 \cdot 10^{-162}:\\
    \;\;\;\;\sin th\\
    
    \mathbf{elif}\;kx \leq 0.5:\\
    \;\;\;\;\sin th \cdot \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \left(kx \cdot kx\right) \cdot \mathsf{fma}\left(kx \cdot kx, \mathsf{fma}\left(kx \cdot kx, \mathsf{fma}\left(kx \cdot kx, -0.0031746031746031746, 0.044444444444444446\right), -0.3333333333333333\right), 1\right)\right)}}\\
    
    \mathbf{else}:\\
    \;\;\;\;\sin th \cdot \left(\sin ky \cdot \sqrt{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}\right)\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if kx < 1.22000000000000012e-162

      1. Initial program 93.6%

        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      2. Add Preprocessing
      3. Taylor expanded in kx around 0

        \[\leadsto \color{blue}{\sin th} \]
      4. Step-by-step derivation
        1. lower-sin.f6432.9

          \[\leadsto \color{blue}{\sin th} \]
      5. Simplified32.9%

        \[\leadsto \color{blue}{\sin th} \]

      if 1.22000000000000012e-162 < kx < 0.5

      1. Initial program 99.8%

        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      2. Add Preprocessing
      3. Applied egg-rr59.1%

        \[\leadsto \color{blue}{\left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, 0.5 + -0.5 \cdot \cos \left(ky + ky\right)\right)}} \cdot \sin ky\right)} \cdot \sin th \]
      4. Applied egg-rr12.5%

        \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \mathsf{fma}\left(\cos \left(ky + ky\right), -0.5, 0.5\right)\right)}} \cdot \sin th} \]
      5. Step-by-step derivation
        1. lift-+.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \cos \color{blue}{\left(ky + ky\right)} \cdot \frac{-1}{2} + \frac{1}{2}\right)}} \cdot \sin th \]
        2. lift-cos.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \color{blue}{\cos \left(ky + ky\right)} \cdot \frac{-1}{2} + \frac{1}{2}\right)}} \cdot \sin th \]
        3. lift-fma.f6412.5

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \color{blue}{\mathsf{fma}\left(\cos \left(ky + ky\right), -0.5, 0.5\right)}\right)}} \cdot \sin th \]
        4. lift-+.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \color{blue}{\left(ky + ky\right)}, \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        5. flip-+N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \color{blue}{\left(\frac{ky \cdot ky - ky \cdot ky}{ky - ky}\right)}, \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        6. lift-*.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \left(\frac{\color{blue}{ky \cdot ky} - ky \cdot ky}{ky - ky}\right), \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        7. lift-*.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \left(\frac{ky \cdot ky - \color{blue}{ky \cdot ky}}{ky - ky}\right), \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        8. +-inversesN/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \left(\frac{\color{blue}{0}}{ky - ky}\right), \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        9. +-inversesN/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \left(\frac{\color{blue}{kx \cdot kx - kx \cdot kx}}{ky - ky}\right), \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        10. +-inversesN/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \left(\frac{kx \cdot kx - kx \cdot kx}{\color{blue}{0}}\right), \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        11. +-inversesN/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \left(\frac{kx \cdot kx - kx \cdot kx}{\color{blue}{kx - kx}}\right), \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        12. flip-+N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \color{blue}{\left(kx + kx\right)}, \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        13. lift-+.f6459.2

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \mathsf{fma}\left(\cos \color{blue}{\left(kx + kx\right)}, -0.5, 0.5\right)\right)}} \cdot \sin th \]
      6. Applied egg-rr59.2%

        \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \color{blue}{\mathsf{fma}\left(\cos \left(kx + kx\right), -0.5, 0.5\right)}\right)}} \cdot \sin th \]
      7. Taylor expanded in kx around 0

        \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \color{blue}{{kx}^{2} \cdot \left(1 + {kx}^{2} \cdot \left({kx}^{2} \cdot \left(\frac{2}{45} + \frac{-1}{315} \cdot {kx}^{2}\right) - \frac{1}{3}\right)\right)}\right)}} \cdot \sin th \]
      8. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \color{blue}{{kx}^{2} \cdot \left(1 + {kx}^{2} \cdot \left({kx}^{2} \cdot \left(\frac{2}{45} + \frac{-1}{315} \cdot {kx}^{2}\right) - \frac{1}{3}\right)\right)}\right)}} \cdot \sin th \]
        2. unpow2N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \color{blue}{\left(kx \cdot kx\right)} \cdot \left(1 + {kx}^{2} \cdot \left({kx}^{2} \cdot \left(\frac{2}{45} + \frac{-1}{315} \cdot {kx}^{2}\right) - \frac{1}{3}\right)\right)\right)}} \cdot \sin th \]
        3. lower-*.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \color{blue}{\left(kx \cdot kx\right)} \cdot \left(1 + {kx}^{2} \cdot \left({kx}^{2} \cdot \left(\frac{2}{45} + \frac{-1}{315} \cdot {kx}^{2}\right) - \frac{1}{3}\right)\right)\right)}} \cdot \sin th \]
        4. +-commutativeN/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \left(kx \cdot kx\right) \cdot \color{blue}{\left({kx}^{2} \cdot \left({kx}^{2} \cdot \left(\frac{2}{45} + \frac{-1}{315} \cdot {kx}^{2}\right) - \frac{1}{3}\right) + 1\right)}\right)}} \cdot \sin th \]
        5. lower-fma.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \left(kx \cdot kx\right) \cdot \color{blue}{\mathsf{fma}\left({kx}^{2}, {kx}^{2} \cdot \left(\frac{2}{45} + \frac{-1}{315} \cdot {kx}^{2}\right) - \frac{1}{3}, 1\right)}\right)}} \cdot \sin th \]
        6. unpow2N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \left(kx \cdot kx\right) \cdot \mathsf{fma}\left(\color{blue}{kx \cdot kx}, {kx}^{2} \cdot \left(\frac{2}{45} + \frac{-1}{315} \cdot {kx}^{2}\right) - \frac{1}{3}, 1\right)\right)}} \cdot \sin th \]
        7. lower-*.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \left(kx \cdot kx\right) \cdot \mathsf{fma}\left(\color{blue}{kx \cdot kx}, {kx}^{2} \cdot \left(\frac{2}{45} + \frac{-1}{315} \cdot {kx}^{2}\right) - \frac{1}{3}, 1\right)\right)}} \cdot \sin th \]
        8. sub-negN/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \left(kx \cdot kx\right) \cdot \mathsf{fma}\left(kx \cdot kx, \color{blue}{{kx}^{2} \cdot \left(\frac{2}{45} + \frac{-1}{315} \cdot {kx}^{2}\right) + \left(\mathsf{neg}\left(\frac{1}{3}\right)\right)}, 1\right)\right)}} \cdot \sin th \]
        9. metadata-evalN/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \left(kx \cdot kx\right) \cdot \mathsf{fma}\left(kx \cdot kx, {kx}^{2} \cdot \left(\frac{2}{45} + \frac{-1}{315} \cdot {kx}^{2}\right) + \color{blue}{\frac{-1}{3}}, 1\right)\right)}} \cdot \sin th \]
        10. lower-fma.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \left(kx \cdot kx\right) \cdot \mathsf{fma}\left(kx \cdot kx, \color{blue}{\mathsf{fma}\left({kx}^{2}, \frac{2}{45} + \frac{-1}{315} \cdot {kx}^{2}, \frac{-1}{3}\right)}, 1\right)\right)}} \cdot \sin th \]
        11. unpow2N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \left(kx \cdot kx\right) \cdot \mathsf{fma}\left(kx \cdot kx, \mathsf{fma}\left(\color{blue}{kx \cdot kx}, \frac{2}{45} + \frac{-1}{315} \cdot {kx}^{2}, \frac{-1}{3}\right), 1\right)\right)}} \cdot \sin th \]
        12. lower-*.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \left(kx \cdot kx\right) \cdot \mathsf{fma}\left(kx \cdot kx, \mathsf{fma}\left(\color{blue}{kx \cdot kx}, \frac{2}{45} + \frac{-1}{315} \cdot {kx}^{2}, \frac{-1}{3}\right), 1\right)\right)}} \cdot \sin th \]
        13. +-commutativeN/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \left(kx \cdot kx\right) \cdot \mathsf{fma}\left(kx \cdot kx, \mathsf{fma}\left(kx \cdot kx, \color{blue}{\frac{-1}{315} \cdot {kx}^{2} + \frac{2}{45}}, \frac{-1}{3}\right), 1\right)\right)}} \cdot \sin th \]
        14. *-commutativeN/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \left(kx \cdot kx\right) \cdot \mathsf{fma}\left(kx \cdot kx, \mathsf{fma}\left(kx \cdot kx, \color{blue}{{kx}^{2} \cdot \frac{-1}{315}} + \frac{2}{45}, \frac{-1}{3}\right), 1\right)\right)}} \cdot \sin th \]
        15. lower-fma.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \left(kx \cdot kx\right) \cdot \mathsf{fma}\left(kx \cdot kx, \mathsf{fma}\left(kx \cdot kx, \color{blue}{\mathsf{fma}\left({kx}^{2}, \frac{-1}{315}, \frac{2}{45}\right)}, \frac{-1}{3}\right), 1\right)\right)}} \cdot \sin th \]
        16. unpow2N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \left(kx \cdot kx\right) \cdot \mathsf{fma}\left(kx \cdot kx, \mathsf{fma}\left(kx \cdot kx, \mathsf{fma}\left(\color{blue}{kx \cdot kx}, \frac{-1}{315}, \frac{2}{45}\right), \frac{-1}{3}\right), 1\right)\right)}} \cdot \sin th \]
        17. lower-*.f6491.7

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \left(kx \cdot kx\right) \cdot \mathsf{fma}\left(kx \cdot kx, \mathsf{fma}\left(kx \cdot kx, \mathsf{fma}\left(\color{blue}{kx \cdot kx}, -0.0031746031746031746, 0.044444444444444446\right), -0.3333333333333333\right), 1\right)\right)}} \cdot \sin th \]
      9. Simplified91.7%

        \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \color{blue}{\left(kx \cdot kx\right) \cdot \mathsf{fma}\left(kx \cdot kx, \mathsf{fma}\left(kx \cdot kx, \mathsf{fma}\left(kx \cdot kx, -0.0031746031746031746, 0.044444444444444446\right), -0.3333333333333333\right), 1\right)}\right)}} \cdot \sin th \]

      if 0.5 < kx

      1. Initial program 99.5%

        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      2. Add Preprocessing
      3. Applied egg-rr99.2%

        \[\leadsto \color{blue}{\left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, 0.5 + -0.5 \cdot \cos \left(ky + ky\right)\right)}} \cdot \sin ky\right)} \cdot \sin th \]
      4. Taylor expanded in ky around 0

        \[\leadsto \left(\sqrt{\color{blue}{\frac{2}{1 - \cos \left(2 \cdot kx\right)}}} \cdot \sin ky\right) \cdot \sin th \]
      5. Step-by-step derivation
        1. lower-/.f64N/A

          \[\leadsto \left(\sqrt{\color{blue}{\frac{2}{1 - \cos \left(2 \cdot kx\right)}}} \cdot \sin ky\right) \cdot \sin th \]
        2. metadata-evalN/A

          \[\leadsto \left(\sqrt{\frac{2}{1 - \cos \left(\color{blue}{\left(\mathsf{neg}\left(-2\right)\right)} \cdot kx\right)}} \cdot \sin ky\right) \cdot \sin th \]
        3. distribute-lft-neg-inN/A

          \[\leadsto \left(\sqrt{\frac{2}{1 - \cos \color{blue}{\left(\mathsf{neg}\left(-2 \cdot kx\right)\right)}}} \cdot \sin ky\right) \cdot \sin th \]
        4. lower--.f64N/A

          \[\leadsto \left(\sqrt{\frac{2}{\color{blue}{1 - \cos \left(\mathsf{neg}\left(-2 \cdot kx\right)\right)}}} \cdot \sin ky\right) \cdot \sin th \]
        5. cos-negN/A

          \[\leadsto \left(\sqrt{\frac{2}{1 - \color{blue}{\cos \left(-2 \cdot kx\right)}}} \cdot \sin ky\right) \cdot \sin th \]
        6. lower-cos.f64N/A

          \[\leadsto \left(\sqrt{\frac{2}{1 - \color{blue}{\cos \left(-2 \cdot kx\right)}}} \cdot \sin ky\right) \cdot \sin th \]
        7. *-commutativeN/A

          \[\leadsto \left(\sqrt{\frac{2}{1 - \cos \color{blue}{\left(kx \cdot -2\right)}}} \cdot \sin ky\right) \cdot \sin th \]
        8. lower-*.f6464.9

          \[\leadsto \left(\sqrt{\frac{2}{1 - \cos \color{blue}{\left(kx \cdot -2\right)}}} \cdot \sin ky\right) \cdot \sin th \]
      6. Simplified64.9%

        \[\leadsto \left(\sqrt{\color{blue}{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}} \cdot \sin ky\right) \cdot \sin th \]
    3. Recombined 3 regimes into one program.
    4. Final simplification51.3%

      \[\leadsto \begin{array}{l} \mathbf{if}\;kx \leq 1.22 \cdot 10^{-162}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;kx \leq 0.5:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \left(kx \cdot kx\right) \cdot \mathsf{fma}\left(kx \cdot kx, \mathsf{fma}\left(kx \cdot kx, \mathsf{fma}\left(kx \cdot kx, -0.0031746031746031746, 0.044444444444444446\right), -0.3333333333333333\right), 1\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \left(\sin ky \cdot \sqrt{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}\right)\\ \end{array} \]
    5. Add Preprocessing

    Alternative 28: 43.6% accurate, 1.6× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;kx \leq 1.14 \cdot 10^{-163}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;kx \leq 0.47:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \left(kx \cdot kx\right) \cdot \mathsf{fma}\left(kx \cdot kx, \mathsf{fma}\left(0.044444444444444446, kx \cdot kx, -0.3333333333333333\right), 1\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \left(\sin ky \cdot \sqrt{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}\right)\\ \end{array} \end{array} \]
    (FPCore (kx ky th)
     :precision binary64
     (if (<= kx 1.14e-163)
       (sin th)
       (if (<= kx 0.47)
         (*
          (sin th)
          (/
           (sin ky)
           (sqrt
            (fma
             (- 1.0 (cos (+ ky ky)))
             0.5
             (*
              (* kx kx)
              (fma
               (* kx kx)
               (fma 0.044444444444444446 (* kx kx) -0.3333333333333333)
               1.0))))))
         (* (sin th) (* (sin ky) (sqrt (/ 2.0 (- 1.0 (cos (* kx -2.0))))))))))
    double code(double kx, double ky, double th) {
    	double tmp;
    	if (kx <= 1.14e-163) {
    		tmp = sin(th);
    	} else if (kx <= 0.47) {
    		tmp = sin(th) * (sin(ky) / sqrt(fma((1.0 - cos((ky + ky))), 0.5, ((kx * kx) * fma((kx * kx), fma(0.044444444444444446, (kx * kx), -0.3333333333333333), 1.0)))));
    	} else {
    		tmp = sin(th) * (sin(ky) * sqrt((2.0 / (1.0 - cos((kx * -2.0))))));
    	}
    	return tmp;
    }
    
    function code(kx, ky, th)
    	tmp = 0.0
    	if (kx <= 1.14e-163)
    		tmp = sin(th);
    	elseif (kx <= 0.47)
    		tmp = Float64(sin(th) * Float64(sin(ky) / sqrt(fma(Float64(1.0 - cos(Float64(ky + ky))), 0.5, Float64(Float64(kx * kx) * fma(Float64(kx * kx), fma(0.044444444444444446, Float64(kx * kx), -0.3333333333333333), 1.0))))));
    	else
    		tmp = Float64(sin(th) * Float64(sin(ky) * sqrt(Float64(2.0 / Float64(1.0 - cos(Float64(kx * -2.0)))))));
    	end
    	return tmp
    end
    
    code[kx_, ky_, th_] := If[LessEqual[kx, 1.14e-163], N[Sin[th], $MachinePrecision], If[LessEqual[kx, 0.47], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(1.0 - N[Cos[N[(ky + ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 0.5 + N[(N[(kx * kx), $MachinePrecision] * N[(N[(kx * kx), $MachinePrecision] * N[(0.044444444444444446 * N[(kx * kx), $MachinePrecision] + -0.3333333333333333), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] * N[Sqrt[N[(2.0 / N[(1.0 - N[Cos[N[(kx * -2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;kx \leq 1.14 \cdot 10^{-163}:\\
    \;\;\;\;\sin th\\
    
    \mathbf{elif}\;kx \leq 0.47:\\
    \;\;\;\;\sin th \cdot \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \left(kx \cdot kx\right) \cdot \mathsf{fma}\left(kx \cdot kx, \mathsf{fma}\left(0.044444444444444446, kx \cdot kx, -0.3333333333333333\right), 1\right)\right)}}\\
    
    \mathbf{else}:\\
    \;\;\;\;\sin th \cdot \left(\sin ky \cdot \sqrt{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}\right)\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if kx < 1.14000000000000005e-163

      1. Initial program 93.6%

        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      2. Add Preprocessing
      3. Taylor expanded in kx around 0

        \[\leadsto \color{blue}{\sin th} \]
      4. Step-by-step derivation
        1. lower-sin.f6432.9

          \[\leadsto \color{blue}{\sin th} \]
      5. Simplified32.9%

        \[\leadsto \color{blue}{\sin th} \]

      if 1.14000000000000005e-163 < kx < 0.46999999999999997

      1. Initial program 99.8%

        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      2. Add Preprocessing
      3. Applied egg-rr59.1%

        \[\leadsto \color{blue}{\left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, 0.5 + -0.5 \cdot \cos \left(ky + ky\right)\right)}} \cdot \sin ky\right)} \cdot \sin th \]
      4. Applied egg-rr12.5%

        \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \mathsf{fma}\left(\cos \left(ky + ky\right), -0.5, 0.5\right)\right)}} \cdot \sin th} \]
      5. Step-by-step derivation
        1. lift-+.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \cos \color{blue}{\left(ky + ky\right)} \cdot \frac{-1}{2} + \frac{1}{2}\right)}} \cdot \sin th \]
        2. lift-cos.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \color{blue}{\cos \left(ky + ky\right)} \cdot \frac{-1}{2} + \frac{1}{2}\right)}} \cdot \sin th \]
        3. lift-fma.f6412.5

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \color{blue}{\mathsf{fma}\left(\cos \left(ky + ky\right), -0.5, 0.5\right)}\right)}} \cdot \sin th \]
        4. lift-+.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \color{blue}{\left(ky + ky\right)}, \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        5. flip-+N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \color{blue}{\left(\frac{ky \cdot ky - ky \cdot ky}{ky - ky}\right)}, \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        6. lift-*.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \left(\frac{\color{blue}{ky \cdot ky} - ky \cdot ky}{ky - ky}\right), \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        7. lift-*.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \left(\frac{ky \cdot ky - \color{blue}{ky \cdot ky}}{ky - ky}\right), \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        8. +-inversesN/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \left(\frac{\color{blue}{0}}{ky - ky}\right), \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        9. +-inversesN/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \left(\frac{\color{blue}{kx \cdot kx - kx \cdot kx}}{ky - ky}\right), \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        10. +-inversesN/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \left(\frac{kx \cdot kx - kx \cdot kx}{\color{blue}{0}}\right), \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        11. +-inversesN/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \left(\frac{kx \cdot kx - kx \cdot kx}{\color{blue}{kx - kx}}\right), \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        12. flip-+N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \color{blue}{\left(kx + kx\right)}, \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        13. lift-+.f6459.2

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \mathsf{fma}\left(\cos \color{blue}{\left(kx + kx\right)}, -0.5, 0.5\right)\right)}} \cdot \sin th \]
      6. Applied egg-rr59.2%

        \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \color{blue}{\mathsf{fma}\left(\cos \left(kx + kx\right), -0.5, 0.5\right)}\right)}} \cdot \sin th \]
      7. Taylor expanded in kx around 0

        \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \color{blue}{{kx}^{2} \cdot \left(1 + {kx}^{2} \cdot \left(\frac{2}{45} \cdot {kx}^{2} - \frac{1}{3}\right)\right)}\right)}} \cdot \sin th \]
      8. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \color{blue}{{kx}^{2} \cdot \left(1 + {kx}^{2} \cdot \left(\frac{2}{45} \cdot {kx}^{2} - \frac{1}{3}\right)\right)}\right)}} \cdot \sin th \]
        2. unpow2N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \color{blue}{\left(kx \cdot kx\right)} \cdot \left(1 + {kx}^{2} \cdot \left(\frac{2}{45} \cdot {kx}^{2} - \frac{1}{3}\right)\right)\right)}} \cdot \sin th \]
        3. lower-*.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \color{blue}{\left(kx \cdot kx\right)} \cdot \left(1 + {kx}^{2} \cdot \left(\frac{2}{45} \cdot {kx}^{2} - \frac{1}{3}\right)\right)\right)}} \cdot \sin th \]
        4. +-commutativeN/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \left(kx \cdot kx\right) \cdot \color{blue}{\left({kx}^{2} \cdot \left(\frac{2}{45} \cdot {kx}^{2} - \frac{1}{3}\right) + 1\right)}\right)}} \cdot \sin th \]
        5. lower-fma.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \left(kx \cdot kx\right) \cdot \color{blue}{\mathsf{fma}\left({kx}^{2}, \frac{2}{45} \cdot {kx}^{2} - \frac{1}{3}, 1\right)}\right)}} \cdot \sin th \]
        6. unpow2N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \left(kx \cdot kx\right) \cdot \mathsf{fma}\left(\color{blue}{kx \cdot kx}, \frac{2}{45} \cdot {kx}^{2} - \frac{1}{3}, 1\right)\right)}} \cdot \sin th \]
        7. lower-*.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \left(kx \cdot kx\right) \cdot \mathsf{fma}\left(\color{blue}{kx \cdot kx}, \frac{2}{45} \cdot {kx}^{2} - \frac{1}{3}, 1\right)\right)}} \cdot \sin th \]
        8. sub-negN/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \left(kx \cdot kx\right) \cdot \mathsf{fma}\left(kx \cdot kx, \color{blue}{\frac{2}{45} \cdot {kx}^{2} + \left(\mathsf{neg}\left(\frac{1}{3}\right)\right)}, 1\right)\right)}} \cdot \sin th \]
        9. metadata-evalN/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \left(kx \cdot kx\right) \cdot \mathsf{fma}\left(kx \cdot kx, \frac{2}{45} \cdot {kx}^{2} + \color{blue}{\frac{-1}{3}}, 1\right)\right)}} \cdot \sin th \]
        10. lower-fma.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \left(kx \cdot kx\right) \cdot \mathsf{fma}\left(kx \cdot kx, \color{blue}{\mathsf{fma}\left(\frac{2}{45}, {kx}^{2}, \frac{-1}{3}\right)}, 1\right)\right)}} \cdot \sin th \]
        11. unpow2N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \left(kx \cdot kx\right) \cdot \mathsf{fma}\left(kx \cdot kx, \mathsf{fma}\left(\frac{2}{45}, \color{blue}{kx \cdot kx}, \frac{-1}{3}\right), 1\right)\right)}} \cdot \sin th \]
        12. lower-*.f6491.5

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \left(kx \cdot kx\right) \cdot \mathsf{fma}\left(kx \cdot kx, \mathsf{fma}\left(0.044444444444444446, \color{blue}{kx \cdot kx}, -0.3333333333333333\right), 1\right)\right)}} \cdot \sin th \]
      9. Simplified91.5%

        \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \color{blue}{\left(kx \cdot kx\right) \cdot \mathsf{fma}\left(kx \cdot kx, \mathsf{fma}\left(0.044444444444444446, kx \cdot kx, -0.3333333333333333\right), 1\right)}\right)}} \cdot \sin th \]

      if 0.46999999999999997 < kx

      1. Initial program 99.5%

        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      2. Add Preprocessing
      3. Applied egg-rr99.2%

        \[\leadsto \color{blue}{\left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, 0.5 + -0.5 \cdot \cos \left(ky + ky\right)\right)}} \cdot \sin ky\right)} \cdot \sin th \]
      4. Taylor expanded in ky around 0

        \[\leadsto \left(\sqrt{\color{blue}{\frac{2}{1 - \cos \left(2 \cdot kx\right)}}} \cdot \sin ky\right) \cdot \sin th \]
      5. Step-by-step derivation
        1. lower-/.f64N/A

          \[\leadsto \left(\sqrt{\color{blue}{\frac{2}{1 - \cos \left(2 \cdot kx\right)}}} \cdot \sin ky\right) \cdot \sin th \]
        2. metadata-evalN/A

          \[\leadsto \left(\sqrt{\frac{2}{1 - \cos \left(\color{blue}{\left(\mathsf{neg}\left(-2\right)\right)} \cdot kx\right)}} \cdot \sin ky\right) \cdot \sin th \]
        3. distribute-lft-neg-inN/A

          \[\leadsto \left(\sqrt{\frac{2}{1 - \cos \color{blue}{\left(\mathsf{neg}\left(-2 \cdot kx\right)\right)}}} \cdot \sin ky\right) \cdot \sin th \]
        4. lower--.f64N/A

          \[\leadsto \left(\sqrt{\frac{2}{\color{blue}{1 - \cos \left(\mathsf{neg}\left(-2 \cdot kx\right)\right)}}} \cdot \sin ky\right) \cdot \sin th \]
        5. cos-negN/A

          \[\leadsto \left(\sqrt{\frac{2}{1 - \color{blue}{\cos \left(-2 \cdot kx\right)}}} \cdot \sin ky\right) \cdot \sin th \]
        6. lower-cos.f64N/A

          \[\leadsto \left(\sqrt{\frac{2}{1 - \color{blue}{\cos \left(-2 \cdot kx\right)}}} \cdot \sin ky\right) \cdot \sin th \]
        7. *-commutativeN/A

          \[\leadsto \left(\sqrt{\frac{2}{1 - \cos \color{blue}{\left(kx \cdot -2\right)}}} \cdot \sin ky\right) \cdot \sin th \]
        8. lower-*.f6464.9

          \[\leadsto \left(\sqrt{\frac{2}{1 - \cos \color{blue}{\left(kx \cdot -2\right)}}} \cdot \sin ky\right) \cdot \sin th \]
      6. Simplified64.9%

        \[\leadsto \left(\sqrt{\color{blue}{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}} \cdot \sin ky\right) \cdot \sin th \]
    3. Recombined 3 regimes into one program.
    4. Final simplification51.2%

      \[\leadsto \begin{array}{l} \mathbf{if}\;kx \leq 1.14 \cdot 10^{-163}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;kx \leq 0.47:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \left(kx \cdot kx\right) \cdot \mathsf{fma}\left(kx \cdot kx, \mathsf{fma}\left(0.044444444444444446, kx \cdot kx, -0.3333333333333333\right), 1\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \left(\sin ky \cdot \sqrt{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}\right)\\ \end{array} \]
    5. Add Preprocessing

    Alternative 29: 43.5% accurate, 1.7× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;kx \leq 1.15 \cdot 10^{-165}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;kx \leq 0.09:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \left(kx \cdot kx\right) \cdot \mathsf{fma}\left(-0.3333333333333333, kx \cdot kx, 1\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \left(\sin ky \cdot \sqrt{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}\right)\\ \end{array} \end{array} \]
    (FPCore (kx ky th)
     :precision binary64
     (if (<= kx 1.15e-165)
       (sin th)
       (if (<= kx 0.09)
         (*
          (sin th)
          (/
           (sin ky)
           (sqrt
            (fma
             (- 1.0 (cos (+ ky ky)))
             0.5
             (* (* kx kx) (fma -0.3333333333333333 (* kx kx) 1.0))))))
         (* (sin th) (* (sin ky) (sqrt (/ 2.0 (- 1.0 (cos (* kx -2.0))))))))))
    double code(double kx, double ky, double th) {
    	double tmp;
    	if (kx <= 1.15e-165) {
    		tmp = sin(th);
    	} else if (kx <= 0.09) {
    		tmp = sin(th) * (sin(ky) / sqrt(fma((1.0 - cos((ky + ky))), 0.5, ((kx * kx) * fma(-0.3333333333333333, (kx * kx), 1.0)))));
    	} else {
    		tmp = sin(th) * (sin(ky) * sqrt((2.0 / (1.0 - cos((kx * -2.0))))));
    	}
    	return tmp;
    }
    
    function code(kx, ky, th)
    	tmp = 0.0
    	if (kx <= 1.15e-165)
    		tmp = sin(th);
    	elseif (kx <= 0.09)
    		tmp = Float64(sin(th) * Float64(sin(ky) / sqrt(fma(Float64(1.0 - cos(Float64(ky + ky))), 0.5, Float64(Float64(kx * kx) * fma(-0.3333333333333333, Float64(kx * kx), 1.0))))));
    	else
    		tmp = Float64(sin(th) * Float64(sin(ky) * sqrt(Float64(2.0 / Float64(1.0 - cos(Float64(kx * -2.0)))))));
    	end
    	return tmp
    end
    
    code[kx_, ky_, th_] := If[LessEqual[kx, 1.15e-165], N[Sin[th], $MachinePrecision], If[LessEqual[kx, 0.09], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(1.0 - N[Cos[N[(ky + ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 0.5 + N[(N[(kx * kx), $MachinePrecision] * N[(-0.3333333333333333 * N[(kx * kx), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] * N[Sqrt[N[(2.0 / N[(1.0 - N[Cos[N[(kx * -2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;kx \leq 1.15 \cdot 10^{-165}:\\
    \;\;\;\;\sin th\\
    
    \mathbf{elif}\;kx \leq 0.09:\\
    \;\;\;\;\sin th \cdot \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \left(kx \cdot kx\right) \cdot \mathsf{fma}\left(-0.3333333333333333, kx \cdot kx, 1\right)\right)}}\\
    
    \mathbf{else}:\\
    \;\;\;\;\sin th \cdot \left(\sin ky \cdot \sqrt{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}\right)\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if kx < 1.15e-165

      1. Initial program 93.6%

        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      2. Add Preprocessing
      3. Taylor expanded in kx around 0

        \[\leadsto \color{blue}{\sin th} \]
      4. Step-by-step derivation
        1. lower-sin.f6432.9

          \[\leadsto \color{blue}{\sin th} \]
      5. Simplified32.9%

        \[\leadsto \color{blue}{\sin th} \]

      if 1.15e-165 < kx < 0.089999999999999997

      1. Initial program 99.8%

        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      2. Add Preprocessing
      3. Applied egg-rr59.1%

        \[\leadsto \color{blue}{\left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, 0.5 + -0.5 \cdot \cos \left(ky + ky\right)\right)}} \cdot \sin ky\right)} \cdot \sin th \]
      4. Applied egg-rr12.5%

        \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \mathsf{fma}\left(\cos \left(ky + ky\right), -0.5, 0.5\right)\right)}} \cdot \sin th} \]
      5. Step-by-step derivation
        1. lift-+.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \cos \color{blue}{\left(ky + ky\right)} \cdot \frac{-1}{2} + \frac{1}{2}\right)}} \cdot \sin th \]
        2. lift-cos.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \color{blue}{\cos \left(ky + ky\right)} \cdot \frac{-1}{2} + \frac{1}{2}\right)}} \cdot \sin th \]
        3. lift-fma.f6412.5

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \color{blue}{\mathsf{fma}\left(\cos \left(ky + ky\right), -0.5, 0.5\right)}\right)}} \cdot \sin th \]
        4. lift-+.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \color{blue}{\left(ky + ky\right)}, \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        5. flip-+N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \color{blue}{\left(\frac{ky \cdot ky - ky \cdot ky}{ky - ky}\right)}, \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        6. lift-*.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \left(\frac{\color{blue}{ky \cdot ky} - ky \cdot ky}{ky - ky}\right), \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        7. lift-*.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \left(\frac{ky \cdot ky - \color{blue}{ky \cdot ky}}{ky - ky}\right), \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        8. +-inversesN/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \left(\frac{\color{blue}{0}}{ky - ky}\right), \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        9. +-inversesN/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \left(\frac{\color{blue}{kx \cdot kx - kx \cdot kx}}{ky - ky}\right), \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        10. +-inversesN/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \left(\frac{kx \cdot kx - kx \cdot kx}{\color{blue}{0}}\right), \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        11. +-inversesN/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \left(\frac{kx \cdot kx - kx \cdot kx}{\color{blue}{kx - kx}}\right), \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        12. flip-+N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \color{blue}{\left(kx + kx\right)}, \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        13. lift-+.f6459.2

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \mathsf{fma}\left(\cos \color{blue}{\left(kx + kx\right)}, -0.5, 0.5\right)\right)}} \cdot \sin th \]
      6. Applied egg-rr59.2%

        \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \color{blue}{\mathsf{fma}\left(\cos \left(kx + kx\right), -0.5, 0.5\right)}\right)}} \cdot \sin th \]
      7. Taylor expanded in kx around 0

        \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \color{blue}{{kx}^{2} \cdot \left(1 + \frac{-1}{3} \cdot {kx}^{2}\right)}\right)}} \cdot \sin th \]
      8. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \color{blue}{{kx}^{2} \cdot \left(1 + \frac{-1}{3} \cdot {kx}^{2}\right)}\right)}} \cdot \sin th \]
        2. unpow2N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \color{blue}{\left(kx \cdot kx\right)} \cdot \left(1 + \frac{-1}{3} \cdot {kx}^{2}\right)\right)}} \cdot \sin th \]
        3. lower-*.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \color{blue}{\left(kx \cdot kx\right)} \cdot \left(1 + \frac{-1}{3} \cdot {kx}^{2}\right)\right)}} \cdot \sin th \]
        4. +-commutativeN/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \left(kx \cdot kx\right) \cdot \color{blue}{\left(\frac{-1}{3} \cdot {kx}^{2} + 1\right)}\right)}} \cdot \sin th \]
        5. lower-fma.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \left(kx \cdot kx\right) \cdot \color{blue}{\mathsf{fma}\left(\frac{-1}{3}, {kx}^{2}, 1\right)}\right)}} \cdot \sin th \]
        6. unpow2N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \left(kx \cdot kx\right) \cdot \mathsf{fma}\left(\frac{-1}{3}, \color{blue}{kx \cdot kx}, 1\right)\right)}} \cdot \sin th \]
        7. lower-*.f6491.0

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \left(kx \cdot kx\right) \cdot \mathsf{fma}\left(-0.3333333333333333, \color{blue}{kx \cdot kx}, 1\right)\right)}} \cdot \sin th \]
      9. Simplified91.0%

        \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \color{blue}{\left(kx \cdot kx\right) \cdot \mathsf{fma}\left(-0.3333333333333333, kx \cdot kx, 1\right)}\right)}} \cdot \sin th \]

      if 0.089999999999999997 < kx

      1. Initial program 99.5%

        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      2. Add Preprocessing
      3. Applied egg-rr99.2%

        \[\leadsto \color{blue}{\left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, 0.5 + -0.5 \cdot \cos \left(ky + ky\right)\right)}} \cdot \sin ky\right)} \cdot \sin th \]
      4. Taylor expanded in ky around 0

        \[\leadsto \left(\sqrt{\color{blue}{\frac{2}{1 - \cos \left(2 \cdot kx\right)}}} \cdot \sin ky\right) \cdot \sin th \]
      5. Step-by-step derivation
        1. lower-/.f64N/A

          \[\leadsto \left(\sqrt{\color{blue}{\frac{2}{1 - \cos \left(2 \cdot kx\right)}}} \cdot \sin ky\right) \cdot \sin th \]
        2. metadata-evalN/A

          \[\leadsto \left(\sqrt{\frac{2}{1 - \cos \left(\color{blue}{\left(\mathsf{neg}\left(-2\right)\right)} \cdot kx\right)}} \cdot \sin ky\right) \cdot \sin th \]
        3. distribute-lft-neg-inN/A

          \[\leadsto \left(\sqrt{\frac{2}{1 - \cos \color{blue}{\left(\mathsf{neg}\left(-2 \cdot kx\right)\right)}}} \cdot \sin ky\right) \cdot \sin th \]
        4. lower--.f64N/A

          \[\leadsto \left(\sqrt{\frac{2}{\color{blue}{1 - \cos \left(\mathsf{neg}\left(-2 \cdot kx\right)\right)}}} \cdot \sin ky\right) \cdot \sin th \]
        5. cos-negN/A

          \[\leadsto \left(\sqrt{\frac{2}{1 - \color{blue}{\cos \left(-2 \cdot kx\right)}}} \cdot \sin ky\right) \cdot \sin th \]
        6. lower-cos.f64N/A

          \[\leadsto \left(\sqrt{\frac{2}{1 - \color{blue}{\cos \left(-2 \cdot kx\right)}}} \cdot \sin ky\right) \cdot \sin th \]
        7. *-commutativeN/A

          \[\leadsto \left(\sqrt{\frac{2}{1 - \cos \color{blue}{\left(kx \cdot -2\right)}}} \cdot \sin ky\right) \cdot \sin th \]
        8. lower-*.f6464.9

          \[\leadsto \left(\sqrt{\frac{2}{1 - \cos \color{blue}{\left(kx \cdot -2\right)}}} \cdot \sin ky\right) \cdot \sin th \]
      6. Simplified64.9%

        \[\leadsto \left(\sqrt{\color{blue}{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}} \cdot \sin ky\right) \cdot \sin th \]
    3. Recombined 3 regimes into one program.
    4. Final simplification51.2%

      \[\leadsto \begin{array}{l} \mathbf{if}\;kx \leq 1.15 \cdot 10^{-165}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;kx \leq 0.09:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \left(kx \cdot kx\right) \cdot \mathsf{fma}\left(-0.3333333333333333, kx \cdot kx, 1\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \left(\sin ky \cdot \sqrt{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}\right)\\ \end{array} \]
    5. Add Preprocessing

    Alternative 30: 44.7% accurate, 1.8× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 4.2 \cdot 10^{-152}:\\ \;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{elif}\;ky \leq 0.0024:\\ \;\;\;\;\sin th \cdot \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \mathsf{fma}\left(0.008333333333333333, ky \cdot ky, -0.16666666666666666\right), ky\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sqrt{0.5 \cdot \left(1 - \cos \left(ky \cdot -2\right)\right)}}\\ \end{array} \end{array} \]
    (FPCore (kx ky th)
     :precision binary64
     (if (<= ky 4.2e-152)
       (* ky (/ (sin th) (sin kx)))
       (if (<= ky 0.0024)
         (*
          (sin th)
          (*
           (sqrt (/ 1.0 (fma (- 1.0 (cos (+ kx kx))) 0.5 (* ky ky))))
           (fma
            ky
            (* (* ky ky) (fma 0.008333333333333333 (* ky ky) -0.16666666666666666))
            ky)))
         (* (sin th) (/ (sin ky) (sqrt (* 0.5 (- 1.0 (cos (* ky -2.0))))))))))
    double code(double kx, double ky, double th) {
    	double tmp;
    	if (ky <= 4.2e-152) {
    		tmp = ky * (sin(th) / sin(kx));
    	} else if (ky <= 0.0024) {
    		tmp = sin(th) * (sqrt((1.0 / fma((1.0 - cos((kx + kx))), 0.5, (ky * ky)))) * fma(ky, ((ky * ky) * fma(0.008333333333333333, (ky * ky), -0.16666666666666666)), ky));
    	} else {
    		tmp = sin(th) * (sin(ky) / sqrt((0.5 * (1.0 - cos((ky * -2.0))))));
    	}
    	return tmp;
    }
    
    function code(kx, ky, th)
    	tmp = 0.0
    	if (ky <= 4.2e-152)
    		tmp = Float64(ky * Float64(sin(th) / sin(kx)));
    	elseif (ky <= 0.0024)
    		tmp = Float64(sin(th) * Float64(sqrt(Float64(1.0 / fma(Float64(1.0 - cos(Float64(kx + kx))), 0.5, Float64(ky * ky)))) * fma(ky, Float64(Float64(ky * ky) * fma(0.008333333333333333, Float64(ky * ky), -0.16666666666666666)), ky)));
    	else
    		tmp = Float64(sin(th) * Float64(sin(ky) / sqrt(Float64(0.5 * Float64(1.0 - cos(Float64(ky * -2.0)))))));
    	end
    	return tmp
    end
    
    code[kx_, ky_, th_] := If[LessEqual[ky, 4.2e-152], N[(ky * N[(N[Sin[th], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[ky, 0.0024], N[(N[Sin[th], $MachinePrecision] * N[(N[Sqrt[N[(1.0 / N[(N[(1.0 - N[Cos[N[(kx + kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 0.5 + N[(ky * ky), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(ky * N[(N[(ky * ky), $MachinePrecision] * N[(0.008333333333333333 * N[(ky * ky), $MachinePrecision] + -0.16666666666666666), $MachinePrecision]), $MachinePrecision] + ky), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(0.5 * N[(1.0 - N[Cos[N[(ky * -2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;ky \leq 4.2 \cdot 10^{-152}:\\
    \;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\
    
    \mathbf{elif}\;ky \leq 0.0024:\\
    \;\;\;\;\sin th \cdot \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \mathsf{fma}\left(0.008333333333333333, ky \cdot ky, -0.16666666666666666\right), ky\right)\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;\sin th \cdot \frac{\sin ky}{\sqrt{0.5 \cdot \left(1 - \cos \left(ky \cdot -2\right)\right)}}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if ky < 4.19999999999999998e-152

      1. Initial program 93.5%

        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      2. Add Preprocessing
      3. Taylor expanded in ky around 0

        \[\leadsto \color{blue}{ky \cdot \left({ky}^{2} \cdot \left(\frac{-1}{2} \cdot \frac{\sin th}{{\sin kx}^{3}} + \frac{-1}{6} \cdot \frac{\sin th}{\sin kx}\right) + \frac{\sin th}{\sin kx}\right)} \]
      4. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto \color{blue}{ky \cdot \left({ky}^{2} \cdot \left(\frac{-1}{2} \cdot \frac{\sin th}{{\sin kx}^{3}} + \frac{-1}{6} \cdot \frac{\sin th}{\sin kx}\right) + \frac{\sin th}{\sin kx}\right)} \]
        2. distribute-lft-inN/A

          \[\leadsto ky \cdot \left(\color{blue}{\left({ky}^{2} \cdot \left(\frac{-1}{2} \cdot \frac{\sin th}{{\sin kx}^{3}}\right) + {ky}^{2} \cdot \left(\frac{-1}{6} \cdot \frac{\sin th}{\sin kx}\right)\right)} + \frac{\sin th}{\sin kx}\right) \]
        3. *-commutativeN/A

          \[\leadsto ky \cdot \left(\left(\color{blue}{\left(\frac{-1}{2} \cdot \frac{\sin th}{{\sin kx}^{3}}\right) \cdot {ky}^{2}} + {ky}^{2} \cdot \left(\frac{-1}{6} \cdot \frac{\sin th}{\sin kx}\right)\right) + \frac{\sin th}{\sin kx}\right) \]
        4. associate-+r+N/A

          \[\leadsto ky \cdot \color{blue}{\left(\left(\frac{-1}{2} \cdot \frac{\sin th}{{\sin kx}^{3}}\right) \cdot {ky}^{2} + \left({ky}^{2} \cdot \left(\frac{-1}{6} \cdot \frac{\sin th}{\sin kx}\right) + \frac{\sin th}{\sin kx}\right)\right)} \]
        5. +-commutativeN/A

          \[\leadsto ky \cdot \color{blue}{\left(\left({ky}^{2} \cdot \left(\frac{-1}{6} \cdot \frac{\sin th}{\sin kx}\right) + \frac{\sin th}{\sin kx}\right) + \left(\frac{-1}{2} \cdot \frac{\sin th}{{\sin kx}^{3}}\right) \cdot {ky}^{2}\right)} \]
      5. Simplified31.4%

        \[\leadsto \color{blue}{ky \cdot \mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right), \frac{\sin th}{\sin kx}, \frac{\left(ky \cdot ky\right) \cdot \left(-0.5 \cdot \sin th\right)}{{\sin kx}^{3}}\right)} \]
      6. Taylor expanded in ky around 0

        \[\leadsto ky \cdot \color{blue}{\frac{\sin th}{\sin kx}} \]
      7. Step-by-step derivation
        1. lower-/.f64N/A

          \[\leadsto ky \cdot \color{blue}{\frac{\sin th}{\sin kx}} \]
        2. lower-sin.f64N/A

          \[\leadsto ky \cdot \frac{\color{blue}{\sin th}}{\sin kx} \]
        3. lower-sin.f6435.0

          \[\leadsto ky \cdot \frac{\sin th}{\color{blue}{\sin kx}} \]
      8. Simplified35.0%

        \[\leadsto ky \cdot \color{blue}{\frac{\sin th}{\sin kx}} \]

      if 4.19999999999999998e-152 < ky < 0.00239999999999999979

      1. Initial program 99.5%

        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      2. Add Preprocessing
      3. Applied egg-rr62.3%

        \[\leadsto \color{blue}{\left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, 0.5 + -0.5 \cdot \cos \left(ky + ky\right)\right)}} \cdot \sin ky\right)} \cdot \sin th \]
      4. Taylor expanded in ky around 0

        \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, \color{blue}{{ky}^{2}}\right)}} \cdot \sin ky\right) \cdot \sin th \]
      5. Step-by-step derivation
        1. unpow2N/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, \color{blue}{ky \cdot ky}\right)}} \cdot \sin ky\right) \cdot \sin th \]
        2. lower-*.f6488.5

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, \color{blue}{ky \cdot ky}\right)}} \cdot \sin ky\right) \cdot \sin th \]
      6. Simplified88.5%

        \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, \color{blue}{ky \cdot ky}\right)}} \cdot \sin ky\right) \cdot \sin th \]
      7. Taylor expanded in ky around 0

        \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \color{blue}{\left(ky \cdot \left(1 + {ky}^{2} \cdot \left(\frac{1}{120} \cdot {ky}^{2} - \frac{1}{6}\right)\right)\right)}\right) \cdot \sin th \]
      8. Step-by-step derivation
        1. +-commutativeN/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \left(ky \cdot \color{blue}{\left({ky}^{2} \cdot \left(\frac{1}{120} \cdot {ky}^{2} - \frac{1}{6}\right) + 1\right)}\right)\right) \cdot \sin th \]
        2. distribute-lft-inN/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \color{blue}{\left(ky \cdot \left({ky}^{2} \cdot \left(\frac{1}{120} \cdot {ky}^{2} - \frac{1}{6}\right)\right) + ky \cdot 1\right)}\right) \cdot \sin th \]
        3. *-rgt-identityN/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \left(ky \cdot \left({ky}^{2} \cdot \left(\frac{1}{120} \cdot {ky}^{2} - \frac{1}{6}\right)\right) + \color{blue}{ky}\right)\right) \cdot \sin th \]
        4. lower-fma.f64N/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \color{blue}{\mathsf{fma}\left(ky, {ky}^{2} \cdot \left(\frac{1}{120} \cdot {ky}^{2} - \frac{1}{6}\right), ky\right)}\right) \cdot \sin th \]
        5. lower-*.f64N/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \color{blue}{{ky}^{2} \cdot \left(\frac{1}{120} \cdot {ky}^{2} - \frac{1}{6}\right)}, ky\right)\right) \cdot \sin th \]
        6. unpow2N/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \color{blue}{\left(ky \cdot ky\right)} \cdot \left(\frac{1}{120} \cdot {ky}^{2} - \frac{1}{6}\right), ky\right)\right) \cdot \sin th \]
        7. lower-*.f64N/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \color{blue}{\left(ky \cdot ky\right)} \cdot \left(\frac{1}{120} \cdot {ky}^{2} - \frac{1}{6}\right), ky\right)\right) \cdot \sin th \]
        8. sub-negN/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \color{blue}{\left(\frac{1}{120} \cdot {ky}^{2} + \left(\mathsf{neg}\left(\frac{1}{6}\right)\right)\right)}, ky\right)\right) \cdot \sin th \]
        9. metadata-evalN/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \left(\frac{1}{120} \cdot {ky}^{2} + \color{blue}{\frac{-1}{6}}\right), ky\right)\right) \cdot \sin th \]
        10. lower-fma.f64N/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \color{blue}{\mathsf{fma}\left(\frac{1}{120}, {ky}^{2}, \frac{-1}{6}\right)}, ky\right)\right) \cdot \sin th \]
        11. unpow2N/A

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \mathsf{fma}\left(\frac{1}{120}, \color{blue}{ky \cdot ky}, \frac{-1}{6}\right), ky\right)\right) \cdot \sin th \]
        12. lower-*.f6488.5

          \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \mathsf{fma}\left(0.008333333333333333, \color{blue}{ky \cdot ky}, -0.16666666666666666\right), ky\right)\right) \cdot \sin th \]
      9. Simplified88.5%

        \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, ky \cdot ky\right)}} \cdot \color{blue}{\mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \mathsf{fma}\left(0.008333333333333333, ky \cdot ky, -0.16666666666666666\right), ky\right)}\right) \cdot \sin th \]

      if 0.00239999999999999979 < ky

      1. Initial program 99.7%

        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      2. Add Preprocessing
      3. Applied egg-rr99.2%

        \[\leadsto \color{blue}{\left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, 0.5 + -0.5 \cdot \cos \left(ky + ky\right)\right)}} \cdot \sin ky\right)} \cdot \sin th \]
      4. Applied egg-rr21.4%

        \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \mathsf{fma}\left(\cos \left(ky + ky\right), -0.5, 0.5\right)\right)}} \cdot \sin th} \]
      5. Step-by-step derivation
        1. lift-+.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \cos \color{blue}{\left(ky + ky\right)} \cdot \frac{-1}{2} + \frac{1}{2}\right)}} \cdot \sin th \]
        2. lift-cos.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \color{blue}{\cos \left(ky + ky\right)} \cdot \frac{-1}{2} + \frac{1}{2}\right)}} \cdot \sin th \]
        3. lift-fma.f6421.4

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \color{blue}{\mathsf{fma}\left(\cos \left(ky + ky\right), -0.5, 0.5\right)}\right)}} \cdot \sin th \]
        4. lift-+.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \color{blue}{\left(ky + ky\right)}, \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        5. flip-+N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \color{blue}{\left(\frac{ky \cdot ky - ky \cdot ky}{ky - ky}\right)}, \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        6. lift-*.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \left(\frac{\color{blue}{ky \cdot ky} - ky \cdot ky}{ky - ky}\right), \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        7. lift-*.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \left(\frac{ky \cdot ky - \color{blue}{ky \cdot ky}}{ky - ky}\right), \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        8. +-inversesN/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \left(\frac{\color{blue}{0}}{ky - ky}\right), \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        9. +-inversesN/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \left(\frac{\color{blue}{kx \cdot kx - kx \cdot kx}}{ky - ky}\right), \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        10. +-inversesN/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \left(\frac{kx \cdot kx - kx \cdot kx}{\color{blue}{0}}\right), \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        11. +-inversesN/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \left(\frac{kx \cdot kx - kx \cdot kx}{\color{blue}{kx - kx}}\right), \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        12. flip-+N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), \frac{1}{2}, \mathsf{fma}\left(\cos \color{blue}{\left(kx + kx\right)}, \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
        13. lift-+.f6499.4

          \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \mathsf{fma}\left(\cos \color{blue}{\left(kx + kx\right)}, -0.5, 0.5\right)\right)}} \cdot \sin th \]
      6. Applied egg-rr99.4%

        \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky + ky\right), 0.5, \color{blue}{\mathsf{fma}\left(\cos \left(kx + kx\right), -0.5, 0.5\right)}\right)}} \cdot \sin th \]
      7. Taylor expanded in kx around 0

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\frac{1}{2} \cdot \left(1 - \cos \left(2 \cdot ky\right)\right)}}} \cdot \sin th \]
      8. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\frac{1}{2} \cdot \left(1 - \cos \left(2 \cdot ky\right)\right)}}} \cdot \sin th \]
        2. lower--.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} \cdot \color{blue}{\left(1 - \cos \left(2 \cdot ky\right)\right)}}} \cdot \sin th \]
        3. metadata-evalN/A

          \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} \cdot \left(1 - \cos \left(\color{blue}{\left(\mathsf{neg}\left(-2\right)\right)} \cdot ky\right)\right)}} \cdot \sin th \]
        4. distribute-lft-neg-inN/A

          \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} \cdot \left(1 - \cos \color{blue}{\left(\mathsf{neg}\left(-2 \cdot ky\right)\right)}\right)}} \cdot \sin th \]
        5. cos-negN/A

          \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} \cdot \left(1 - \color{blue}{\cos \left(-2 \cdot ky\right)}\right)}} \cdot \sin th \]
        6. lower-cos.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} \cdot \left(1 - \color{blue}{\cos \left(-2 \cdot ky\right)}\right)}} \cdot \sin th \]
        7. *-commutativeN/A

          \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} \cdot \left(1 - \cos \color{blue}{\left(ky \cdot -2\right)}\right)}} \cdot \sin th \]
        8. lower-*.f6463.6

          \[\leadsto \frac{\sin ky}{\sqrt{0.5 \cdot \left(1 - \cos \color{blue}{\left(ky \cdot -2\right)}\right)}} \cdot \sin th \]
      9. Simplified63.6%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{0.5 \cdot \left(1 - \cos \left(ky \cdot -2\right)\right)}}} \cdot \sin th \]
    3. Recombined 3 regimes into one program.
    4. Final simplification50.8%

      \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq 4.2 \cdot 10^{-152}:\\ \;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{elif}\;ky \leq 0.0024:\\ \;\;\;\;\sin th \cdot \left(\sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, ky \cdot ky\right)}} \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \mathsf{fma}\left(0.008333333333333333, ky \cdot ky, -0.16666666666666666\right), ky\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sqrt{0.5 \cdot \left(1 - \cos \left(ky \cdot -2\right)\right)}}\\ \end{array} \]
    5. Add Preprocessing

    Alternative 31: 13.4% 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 96.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.f6426.0

        \[\leadsto \color{blue}{\sin th} \]
    5. Simplified26.0%

      \[\leadsto \color{blue}{\sin th} \]
    6. Taylor expanded in th around 0

      \[\leadsto \color{blue}{th \cdot \left(1 + \frac{-1}{6} \cdot {th}^{2}\right)} \]
    7. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \color{blue}{th \cdot \left(1 + \frac{-1}{6} \cdot {th}^{2}\right)} \]
      2. +-commutativeN/A

        \[\leadsto th \cdot \color{blue}{\left(\frac{-1}{6} \cdot {th}^{2} + 1\right)} \]
      3. lower-fma.f64N/A

        \[\leadsto th \cdot \color{blue}{\mathsf{fma}\left(\frac{-1}{6}, {th}^{2}, 1\right)} \]
      4. unpow2N/A

        \[\leadsto th \cdot \mathsf{fma}\left(\frac{-1}{6}, \color{blue}{th \cdot th}, 1\right) \]
      5. lower-*.f6414.7

        \[\leadsto th \cdot \mathsf{fma}\left(-0.16666666666666666, \color{blue}{th \cdot th}, 1\right) \]
    8. Simplified14.7%

      \[\leadsto \color{blue}{th \cdot \mathsf{fma}\left(-0.16666666666666666, th \cdot th, 1\right)} \]
    9. Taylor expanded in th around 0

      \[\leadsto th \cdot \color{blue}{1} \]
    10. Step-by-step derivation
      1. Simplified15.1%

        \[\leadsto th \cdot \color{blue}{1} \]
      2. Step-by-step derivation
        1. *-rgt-identity15.1

          \[\leadsto \color{blue}{th} \]
      3. Applied egg-rr15.1%

        \[\leadsto \color{blue}{th} \]
      4. Add Preprocessing

      Reproduce

      ?
      herbie shell --seed 2024207 
      (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)))