Toniolo and Linder, Equation (3b), real

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

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

Initial Program: 94.1% accurate, 1.0× speedup?

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

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

Alternative 1: 99.7% accurate, 1.2× speedup?

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

\\
\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th
\end{array}
Derivation
  1. Initial program 95.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 rewrites99.6%

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

Alternative 2: 78.1% accurate, 0.2× speedup?

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

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

\mathbf{elif}\;t\_4 \leq -0.002:\\
\;\;\;\;\frac{th \cdot \left(\sin ky \cdot \mathsf{fma}\left(-0.16666666666666666, th \cdot th, 1\right)\right)}{t\_5}\\

\mathbf{elif}\;t\_4 \leq 10^{-11}:\\
\;\;\;\;t\_3\\

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

\mathbf{elif}\;t\_4 \leq 1:\\
\;\;\;\;\sin th\\

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


\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))))) < -0.99980000000000002

    1. Initial program 84.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-*.f6484.8

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

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

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

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

    1. Initial program 99.2%

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

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

      \[\leadsto \frac{\color{blue}{th \cdot \left(\sin ky + \frac{-1}{6} \cdot \left({th}^{2} \cdot \sin ky\right)\right)}}{\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)}} \]
    5. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \frac{\color{blue}{th \cdot \left(\sin ky + \frac{-1}{6} \cdot \left({th}^{2} \cdot \sin ky\right)\right)}}{\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)}} \]
      2. associate-*r*N/A

        \[\leadsto \frac{th \cdot \left(\sin ky + \color{blue}{\left(\frac{-1}{6} \cdot {th}^{2}\right) \cdot \sin ky}\right)}{\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)}} \]
      3. distribute-rgt1-inN/A

        \[\leadsto \frac{th \cdot \color{blue}{\left(\left(\frac{-1}{6} \cdot {th}^{2} + 1\right) \cdot \sin ky\right)}}{\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)}} \]
      4. +-commutativeN/A

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

        \[\leadsto \frac{th \cdot \color{blue}{\left(\left(1 + \frac{-1}{6} \cdot {th}^{2}\right) \cdot \sin ky\right)}}{\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)}} \]
      6. +-commutativeN/A

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

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

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

        \[\leadsto \frac{th \cdot \left(\mathsf{fma}\left(\frac{-1}{6}, \color{blue}{th \cdot th}, 1\right) \cdot \sin ky\right)}{\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)}} \]
      10. lower-sin.f6452.4

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

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

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

    1. Initial program 95.1%

      \[\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 rewrites99.6%

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

      \[\leadsto \frac{\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.6

        \[\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. Applied rewrites99.6%

      \[\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 \]
    8. Taylor expanded in ky around 0

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

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

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

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

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

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

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

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

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

    1. Initial program 99.0%

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

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

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

        \[\leadsto \frac{\color{blue}{th \cdot \sin ky}}{\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)}} \]
      2. lower-sin.f6462.5

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

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

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

    1. Initial program 100.0%

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

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

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

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

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

Alternative 3: 78.1% accurate, 0.2× speedup?

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

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

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

\mathbf{elif}\;t\_2 \leq 10^{-11}:\\
\;\;\;\;t\_5\\

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

\mathbf{elif}\;t\_2 \leq 1:\\
\;\;\;\;\sin th\\

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


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

    1. Initial program 84.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-*.f6484.8

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

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

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

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

    1. Initial program 99.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. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\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)}} \cdot \color{blue}{\left(th \cdot \left(1 + \frac{-1}{6} \cdot {th}^{2}\right)\right)} \]
    6. Step-by-step derivation
      1. +-commutativeN/A

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

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

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

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

    1. Initial program 95.1%

      \[\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 rewrites99.6%

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

      \[\leadsto \frac{\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.6

        \[\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. Applied rewrites99.6%

      \[\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 \]
    8. Taylor expanded in ky around 0

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

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

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

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

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

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

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

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

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

    1. Initial program 99.0%

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

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

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

        \[\leadsto \frac{\color{blue}{th \cdot \sin ky}}{\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)}} \]
      2. lower-sin.f6462.5

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

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

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

    1. Initial program 100.0%

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

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

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

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

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

Alternative 4: 78.1% accurate, 0.2× speedup?

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

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

\mathbf{elif}\;t\_1 \leq -0.002:\\
\;\;\;\;t\_5\\

\mathbf{elif}\;t\_1 \leq 10^{-11}:\\
\;\;\;\;t\_4\\

\mathbf{elif}\;t\_1 \leq 0.92:\\
\;\;\;\;t\_5\\

\mathbf{elif}\;t\_1 \leq 1:\\
\;\;\;\;\sin th\\

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


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

    1. Initial program 84.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-*.f6484.8

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

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

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

    if -0.99980000000000002 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -2e-3 or 9.99999999999999939e-12 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 0.92000000000000004

    1. Initial program 99.2%

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

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

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

        \[\leadsto \frac{\color{blue}{th \cdot \sin ky}}{\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)}} \]
      2. lower-sin.f6455.9

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

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

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

    1. Initial program 95.1%

      \[\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 rewrites99.6%

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

      \[\leadsto \frac{\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.6

        \[\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. Applied rewrites99.6%

      \[\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 \]
    8. Taylor expanded in ky around 0

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

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

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

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

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

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

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

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

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

    1. Initial program 100.0%

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

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

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

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

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

Alternative 5: 86.1% 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 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\ t_3 := \sqrt{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, 0.5 + -0.5 \cdot \cos \left(ky + ky\right)\right)}\\ t_4 := ky \cdot \mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right)\\ \mathbf{if}\;t\_2 \leq -0.9998:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_2 \leq -0.002:\\ \;\;\;\;\frac{th \cdot \left(\sin ky \cdot \mathsf{fma}\left(-0.16666666666666666, th \cdot th, 1\right)\right)}{t\_3}\\ \mathbf{elif}\;t\_2 \leq 10^{-11}:\\ \;\;\;\;\sin th \cdot \frac{t\_4}{\mathsf{hypot}\left(t\_4, \sin kx\right)}\\ \mathbf{elif}\;t\_2 \leq 0.996:\\ \;\;\;\;\frac{\sin ky \cdot th}{t\_3}\\ \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 (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))))
        (t_3
         (sqrt
          (fma (- 1.0 (cos (+ kx kx))) 0.5 (+ 0.5 (* -0.5 (cos (+ ky ky)))))))
        (t_4 (* ky (fma (* ky ky) -0.16666666666666666 1.0))))
   (if (<= t_2 -0.9998)
     t_1
     (if (<= t_2 -0.002)
       (/ (* th (* (sin ky) (fma -0.16666666666666666 (* th th) 1.0))) t_3)
       (if (<= t_2 1e-11)
         (* (sin th) (/ t_4 (hypot t_4 (sin kx))))
         (if (<= t_2 0.996) (/ (* (sin ky) th) t_3) t_1))))))
double code(double kx, double ky, double th) {
	double t_1 = sin(th) * (sin(ky) / hypot(sin(ky), kx));
	double t_2 = sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)));
	double t_3 = sqrt(fma((1.0 - cos((kx + kx))), 0.5, (0.5 + (-0.5 * cos((ky + ky))))));
	double t_4 = ky * fma((ky * ky), -0.16666666666666666, 1.0);
	double tmp;
	if (t_2 <= -0.9998) {
		tmp = t_1;
	} else if (t_2 <= -0.002) {
		tmp = (th * (sin(ky) * fma(-0.16666666666666666, (th * th), 1.0))) / t_3;
	} else if (t_2 <= 1e-11) {
		tmp = sin(th) * (t_4 / hypot(t_4, sin(kx)));
	} else if (t_2 <= 0.996) {
		tmp = (sin(ky) * th) / t_3;
	} 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 = Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0))))
	t_3 = sqrt(fma(Float64(1.0 - cos(Float64(kx + kx))), 0.5, Float64(0.5 + Float64(-0.5 * cos(Float64(ky + ky))))))
	t_4 = Float64(ky * fma(Float64(ky * ky), -0.16666666666666666, 1.0))
	tmp = 0.0
	if (t_2 <= -0.9998)
		tmp = t_1;
	elseif (t_2 <= -0.002)
		tmp = Float64(Float64(th * Float64(sin(ky) * fma(-0.16666666666666666, Float64(th * th), 1.0))) / t_3);
	elseif (t_2 <= 1e-11)
		tmp = Float64(sin(th) * Float64(t_4 / hypot(t_4, sin(kx))));
	elseif (t_2 <= 0.996)
		tmp = Float64(Float64(sin(ky) * th) / t_3);
	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[(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$3 = 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]}, Block[{t$95$4 = N[(ky * N[(N[(ky * ky), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -0.9998], t$95$1, If[LessEqual[t$95$2, -0.002], N[(N[(th * N[(N[Sin[ky], $MachinePrecision] * N[(-0.16666666666666666 * N[(th * th), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / t$95$3), $MachinePrecision], If[LessEqual[t$95$2, 1e-11], N[(N[Sin[th], $MachinePrecision] * N[(t$95$4 / N[Sqrt[t$95$4 ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 0.996], N[(N[(N[Sin[ky], $MachinePrecision] * th), $MachinePrecision] / t$95$3), $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 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\
t_3 := \sqrt{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, 0.5 + -0.5 \cdot \cos \left(ky + ky\right)\right)}\\
t_4 := ky \cdot \mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right)\\
\mathbf{if}\;t\_2 \leq -0.9998:\\
\;\;\;\;t\_1\\

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

\mathbf{elif}\;t\_2 \leq 10^{-11}:\\
\;\;\;\;\sin th \cdot \frac{t\_4}{\mathsf{hypot}\left(t\_4, \sin kx\right)}\\

\mathbf{elif}\;t\_2 \leq 0.996:\\
\;\;\;\;\frac{\sin ky \cdot th}{t\_3}\\

\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.99980000000000002 or 0.996 < (/.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 88.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 \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-*.f6486.2

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

      \[\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.f6497.9

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

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

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

    1. Initial program 99.2%

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

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

      \[\leadsto \frac{\color{blue}{th \cdot \left(\sin ky + \frac{-1}{6} \cdot \left({th}^{2} \cdot \sin ky\right)\right)}}{\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)}} \]
    5. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \frac{\color{blue}{th \cdot \left(\sin ky + \frac{-1}{6} \cdot \left({th}^{2} \cdot \sin ky\right)\right)}}{\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)}} \]
      2. associate-*r*N/A

        \[\leadsto \frac{th \cdot \left(\sin ky + \color{blue}{\left(\frac{-1}{6} \cdot {th}^{2}\right) \cdot \sin ky}\right)}{\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)}} \]
      3. distribute-rgt1-inN/A

        \[\leadsto \frac{th \cdot \color{blue}{\left(\left(\frac{-1}{6} \cdot {th}^{2} + 1\right) \cdot \sin ky\right)}}{\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)}} \]
      4. +-commutativeN/A

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

        \[\leadsto \frac{th \cdot \color{blue}{\left(\left(1 + \frac{-1}{6} \cdot {th}^{2}\right) \cdot \sin ky\right)}}{\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)}} \]
      6. +-commutativeN/A

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

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

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

        \[\leadsto \frac{th \cdot \left(\mathsf{fma}\left(\frac{-1}{6}, \color{blue}{th \cdot th}, 1\right) \cdot \sin ky\right)}{\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)}} \]
      10. lower-sin.f6452.4

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

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

    if -2e-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))))) < 9.99999999999999939e-12

    1. Initial program 99.6%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-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 rewrites99.6%

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

      \[\leadsto \frac{\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.6

        \[\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. Applied rewrites99.6%

      \[\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 \]
    8. Taylor expanded in ky around 0

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

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

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

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

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

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

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

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

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

    1. Initial program 99.1%

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

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

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

        \[\leadsto \frac{\color{blue}{th \cdot \sin ky}}{\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)}} \]
      2. lower-sin.f6461.6

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

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

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

Alternative 6: 60.6% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\ \mathbf{if}\;t\_1 \leq -0.7:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sqrt{\mathsf{fma}\left(-0.5, \cos \left(ky \cdot -2\right), 0.5\right)}}\\ \mathbf{elif}\;t\_1 \leq 4 \cdot 10^{-206}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sqrt{0.5 \cdot \left(1 - \cos \left(kx \cdot -2\right)\right)}}\\ \mathbf{elif}\;t\_1 \leq 7 \cdot 10^{-8}:\\ \;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0))))))
   (if (<= t_1 -0.7)
     (* (sin th) (/ (sin ky) (sqrt (fma -0.5 (cos (* ky -2.0)) 0.5))))
     (if (<= t_1 4e-206)
       (* (sin th) (/ (sin ky) (sqrt (* 0.5 (- 1.0 (cos (* kx -2.0)))))))
       (if (<= t_1 7e-8) (* ky (/ (sin th) (sin kx))) (sin th))))))
double code(double kx, double ky, double th) {
	double t_1 = sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)));
	double tmp;
	if (t_1 <= -0.7) {
		tmp = sin(th) * (sin(ky) / sqrt(fma(-0.5, cos((ky * -2.0)), 0.5)));
	} else if (t_1 <= 4e-206) {
		tmp = sin(th) * (sin(ky) / sqrt((0.5 * (1.0 - cos((kx * -2.0))))));
	} else if (t_1 <= 7e-8) {
		tmp = ky * (sin(th) / sin(kx));
	} 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 <= -0.7)
		tmp = Float64(sin(th) * Float64(sin(ky) / sqrt(fma(-0.5, cos(Float64(ky * -2.0)), 0.5))));
	elseif (t_1 <= 4e-206)
		tmp = Float64(sin(th) * Float64(sin(ky) / sqrt(Float64(0.5 * Float64(1.0 - cos(Float64(kx * -2.0)))))));
	elseif (t_1 <= 7e-8)
		tmp = Float64(ky * Float64(sin(th) / sin(kx)));
	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, -0.7], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(-0.5 * N[Cos[N[(ky * -2.0), $MachinePrecision]], $MachinePrecision] + 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 4e-206], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(0.5 * N[(1.0 - N[Cos[N[(kx * -2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 7e-8], N[(ky * N[(N[Sin[th], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]]
\begin{array}{l}

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

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

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

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


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

    1. Initial program 89.3%

      \[\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. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.00000000000000011e-206 < (/.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))))) < 7.00000000000000048e-8

    1. Initial program 99.6%

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

      \[\leadsto \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. associate-+l+N/A

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

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

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

        \[\leadsto ky \cdot \color{blue}{\mathsf{fma}\left(ky, ky \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) + \frac{\sin th}{\sin kx}\right)} \]
    5. Applied rewrites55.0%

      \[\leadsto \color{blue}{ky \cdot \mathsf{fma}\left(ky, \frac{ky \cdot \left(-0.5 \cdot \sin th\right)}{{\sin kx}^{3}}, \mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot \frac{\sin th}{\sin kx}\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.f6454.8

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

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

    if 7.00000000000000048e-8 < (/.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.8%

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

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

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

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

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

Alternative 7: 60.3% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\ \mathbf{if}\;t\_1 \leq -0.002:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sqrt{\mathsf{fma}\left(-0.5, \cos \left(ky \cdot -2\right), 0.5\right)}}\\ \mathbf{elif}\;t\_1 \leq 4 \cdot 10^{-206}:\\ \;\;\;\;\frac{ky \cdot \sin th}{\sqrt{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, ky \cdot ky\right)}}\\ \mathbf{elif}\;t\_1 \leq 7 \cdot 10^{-8}:\\ \;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0))))))
   (if (<= t_1 -0.002)
     (* (sin th) (/ (sin ky) (sqrt (fma -0.5 (cos (* ky -2.0)) 0.5))))
     (if (<= t_1 4e-206)
       (/ (* ky (sin th)) (sqrt (fma (- 1.0 (cos (+ kx kx))) 0.5 (* ky ky))))
       (if (<= t_1 7e-8) (* ky (/ (sin th) (sin kx))) (sin th))))))
double code(double kx, double ky, double th) {
	double t_1 = sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)));
	double tmp;
	if (t_1 <= -0.002) {
		tmp = sin(th) * (sin(ky) / sqrt(fma(-0.5, cos((ky * -2.0)), 0.5)));
	} else if (t_1 <= 4e-206) {
		tmp = (ky * sin(th)) / sqrt(fma((1.0 - cos((kx + kx))), 0.5, (ky * ky)));
	} else if (t_1 <= 7e-8) {
		tmp = ky * (sin(th) / sin(kx));
	} 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 <= -0.002)
		tmp = Float64(sin(th) * Float64(sin(ky) / sqrt(fma(-0.5, cos(Float64(ky * -2.0)), 0.5))));
	elseif (t_1 <= 4e-206)
		tmp = Float64(Float64(ky * sin(th)) / sqrt(fma(Float64(1.0 - cos(Float64(kx + kx))), 0.5, Float64(ky * ky))));
	elseif (t_1 <= 7e-8)
		tmp = Float64(ky * Float64(sin(th) / sin(kx)));
	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, -0.002], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(-0.5 * N[Cos[N[(ky * -2.0), $MachinePrecision]], $MachinePrecision] + 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 4e-206], N[(N[(ky * N[Sin[th], $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(N[(1.0 - N[Cos[N[(kx + kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 0.5 + N[(ky * ky), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 7e-8], N[(ky * N[(N[Sin[th], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]]
\begin{array}{l}

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

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

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

\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))))) < -2e-3

    1. Initial program 91.7%

      \[\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. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\frac{-1}{2} \cdot \cos \left(2 \cdot ky\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 ky\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 ky\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 ky\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 ky\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 ky\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(ky \cdot -2\right)}, \frac{1}{2}\right)}} \cdot \sin th \]
      8. lower-*.f6443.0

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

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

    if -2e-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))))) < 4.00000000000000011e-206

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

    if 4.00000000000000011e-206 < (/.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))))) < 7.00000000000000048e-8

    1. Initial program 99.6%

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

      \[\leadsto \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. associate-+l+N/A

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

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

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

        \[\leadsto ky \cdot \color{blue}{\mathsf{fma}\left(ky, ky \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) + \frac{\sin th}{\sin kx}\right)} \]
    5. Applied rewrites55.0%

      \[\leadsto \color{blue}{ky \cdot \mathsf{fma}\left(ky, \frac{ky \cdot \left(-0.5 \cdot \sin th\right)}{{\sin kx}^{3}}, \mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot \frac{\sin th}{\sin kx}\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.f6454.8

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

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

    if 7.00000000000000048e-8 < (/.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.8%

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

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

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

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

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

Alternative 8: 47.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 -0.002:\\ \;\;\;\;\frac{\sin ky \cdot th}{\sqrt{1 - \cos \left(kx \cdot -2\right)} \cdot \sqrt{0.5}}\\ \mathbf{elif}\;t\_1 \leq 4 \cdot 10^{-206}:\\ \;\;\;\;\frac{ky \cdot \sin th}{\sqrt{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, ky \cdot ky\right)}}\\ \mathbf{elif}\;t\_1 \leq 7 \cdot 10^{-8}:\\ \;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0))))))
   (if (<= t_1 -0.002)
     (/ (* (sin ky) th) (* (sqrt (- 1.0 (cos (* kx -2.0)))) (sqrt 0.5)))
     (if (<= t_1 4e-206)
       (/ (* ky (sin th)) (sqrt (fma (- 1.0 (cos (+ kx kx))) 0.5 (* ky ky))))
       (if (<= t_1 7e-8) (* ky (/ (sin th) (sin kx))) (sin th))))))
double code(double kx, double ky, double th) {
	double t_1 = sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)));
	double tmp;
	if (t_1 <= -0.002) {
		tmp = (sin(ky) * th) / (sqrt((1.0 - cos((kx * -2.0)))) * sqrt(0.5));
	} else if (t_1 <= 4e-206) {
		tmp = (ky * sin(th)) / sqrt(fma((1.0 - cos((kx + kx))), 0.5, (ky * ky)));
	} else if (t_1 <= 7e-8) {
		tmp = ky * (sin(th) / sin(kx));
	} 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 <= -0.002)
		tmp = Float64(Float64(sin(ky) * th) / Float64(sqrt(Float64(1.0 - cos(Float64(kx * -2.0)))) * sqrt(0.5)));
	elseif (t_1 <= 4e-206)
		tmp = Float64(Float64(ky * sin(th)) / sqrt(fma(Float64(1.0 - cos(Float64(kx + kx))), 0.5, Float64(ky * ky))));
	elseif (t_1 <= 7e-8)
		tmp = Float64(ky * Float64(sin(th) / sin(kx)));
	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, -0.002], N[(N[(N[Sin[ky], $MachinePrecision] * th), $MachinePrecision] / N[(N[Sqrt[N[(1.0 - N[Cos[N[(kx * -2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 4e-206], N[(N[(ky * N[Sin[th], $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(N[(1.0 - N[Cos[N[(kx + kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 0.5 + N[(ky * ky), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 7e-8], N[(ky * N[(N[Sin[th], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]]
\begin{array}{l}

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

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

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

\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))))) < -2e-3

    1. Initial program 91.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2e-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))))) < 4.00000000000000011e-206

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

    if 4.00000000000000011e-206 < (/.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))))) < 7.00000000000000048e-8

    1. Initial program 99.6%

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

      \[\leadsto \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. associate-+l+N/A

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

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

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

        \[\leadsto ky \cdot \color{blue}{\mathsf{fma}\left(ky, ky \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) + \frac{\sin th}{\sin kx}\right)} \]
    5. Applied rewrites55.0%

      \[\leadsto \color{blue}{ky \cdot \mathsf{fma}\left(ky, \frac{ky \cdot \left(-0.5 \cdot \sin th\right)}{{\sin kx}^{3}}, \mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot \frac{\sin th}{\sin kx}\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.f6454.8

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

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

    if 7.00000000000000048e-8 < (/.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.8%

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

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

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

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

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

Alternative 9: 54.6% 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 4 \cdot 10^{-206}:\\ \;\;\;\;\frac{ky \cdot \sin th}{\sqrt{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, ky \cdot ky\right)}}\\ \mathbf{elif}\;t\_1 \leq 7 \cdot 10^{-8}:\\ \;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\ \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 4e-206)
     (/ (* ky (sin th)) (sqrt (fma (- 1.0 (cos (+ kx kx))) 0.5 (* ky ky))))
     (if (<= t_1 7e-8) (* ky (/ (sin th) (sin kx))) (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 <= 4e-206) {
		tmp = (ky * sin(th)) / sqrt(fma((1.0 - cos((kx + kx))), 0.5, (ky * ky)));
	} else if (t_1 <= 7e-8) {
		tmp = ky * (sin(th) / sin(kx));
	} 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 <= 4e-206)
		tmp = Float64(Float64(ky * sin(th)) / sqrt(fma(Float64(1.0 - cos(Float64(kx + kx))), 0.5, Float64(ky * ky))));
	elseif (t_1 <= 7e-8)
		tmp = Float64(ky * Float64(sin(th) / sin(kx)));
	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, 4e-206], N[(N[(ky * N[Sin[th], $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(N[(1.0 - N[Cos[N[(kx + kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 0.5 + N[(ky * ky), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 7e-8], N[(ky * N[(N[Sin[th], $MachinePrecision] / N[Sin[kx], $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 4 \cdot 10^{-206}:\\
\;\;\;\;\frac{ky \cdot \sin th}{\sqrt{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, ky \cdot ky\right)}}\\

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

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


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

    1. Initial program 95.1%

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

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

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

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

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

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

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

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

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

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

    if 4.00000000000000011e-206 < (/.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))))) < 7.00000000000000048e-8

    1. Initial program 99.6%

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

      \[\leadsto \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. associate-+l+N/A

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

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

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

        \[\leadsto ky \cdot \color{blue}{\mathsf{fma}\left(ky, ky \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) + \frac{\sin th}{\sin kx}\right)} \]
    5. Applied rewrites55.0%

      \[\leadsto \color{blue}{ky \cdot \mathsf{fma}\left(ky, \frac{ky \cdot \left(-0.5 \cdot \sin th\right)}{{\sin kx}^{3}}, \mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot \frac{\sin th}{\sin kx}\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.f6454.8

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

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

    if 7.00000000000000048e-8 < (/.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.8%

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

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

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

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

Alternative 10: 45.8% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.1:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) 0.1)
   (* (sin th) (/ (sin ky) (sin kx)))
   (sin th)))
double code(double kx, double ky, double th) {
	double tmp;
	if ((sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) <= 0.1) {
		tmp = sin(th) * (sin(ky) / sin(kx));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if ((sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) <= 0.1d0) then
        tmp = sin(th) * (sin(ky) / sin(kx))
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if ((Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) <= 0.1) {
		tmp = Math.sin(th) * (Math.sin(ky) / Math.sin(kx));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if (math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))) <= 0.1:
		tmp = math.sin(th) * (math.sin(ky) / math.sin(kx))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 0.1)
		tmp = Float64(sin(th) * Float64(sin(ky) / sin(kx)));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if ((sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 0.1)
		tmp = sin(th) * (sin(ky) / sin(kx));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 0.1], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $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.1:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\

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


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

    1. Initial program 95.9%

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

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

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

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

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

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

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

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

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

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

Alternative 11: 62.0% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := {\sin kx}^{2}\\ \mathbf{if}\;t\_1 \leq 5 \cdot 10^{-311}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;t\_1 \leq 5 \cdot 10^{-12}:\\ \;\;\;\;\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 \frac{\sin ky}{\sqrt{0.5 \cdot \left(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 5e-311)
     (sin th)
     (if (<= t_1 5e-12)
       (/
        (sin th)
        (/ (sqrt (fma kx kx (fma (cos (+ ky ky)) -0.5 0.5))) (sin ky)))
       (* (sin th) (/ (sin ky) (sqrt (* 0.5 (- 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 <= 5e-311) {
		tmp = sin(th);
	} else if (t_1 <= 5e-12) {
		tmp = sin(th) / (sqrt(fma(kx, kx, fma(cos((ky + ky)), -0.5, 0.5))) / sin(ky));
	} else {
		tmp = sin(th) * (sin(ky) / sqrt((0.5 * (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 <= 5e-311)
		tmp = sin(th);
	elseif (t_1 <= 5e-12)
		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(0.5 * 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, 5e-311], N[Sin[th], $MachinePrecision], If[LessEqual[t$95$1, 5e-12], 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[(0.5 * 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 5 \cdot 10^{-311}:\\
\;\;\;\;\sin th\\

\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{-12}:\\
\;\;\;\;\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 \frac{\sin ky}{\sqrt{0.5 \cdot \left(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)) < 5.00000000000023e-311

    1. Initial program 78.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.f6454.4

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

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

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

    1. Initial program 99.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-*.f6499.9

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

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

      \[\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 4.9999999999999997e-12 < (pow.f64 (sin.f64 kx) #s(literal 2 binary64))

    1. Initial program 99.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{0.5 \cdot \left(1 - \cos \left(kx \cdot -2\right)\right)}}} \cdot \sin th \]
  3. Recombined 3 regimes into one program.
  4. Final simplification67.7%

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

Alternative 12: 62.0% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := {\sin kx}^{2}\\ \mathbf{if}\;t\_1 \leq 5 \cdot 10^{-311}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;t\_1 \leq 5 \cdot 10^{-12}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\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 \frac{\sin ky}{\sqrt{0.5 \cdot \left(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 5e-311)
     (sin th)
     (if (<= t_1 5e-12)
       (*
        (sin th)
        (/ (sin ky) (sqrt (fma kx kx (fma (cos (+ ky ky)) -0.5 0.5)))))
       (* (sin th) (/ (sin ky) (sqrt (* 0.5 (- 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 <= 5e-311) {
		tmp = sin(th);
	} else if (t_1 <= 5e-12) {
		tmp = sin(th) * (sin(ky) / sqrt(fma(kx, kx, fma(cos((ky + ky)), -0.5, 0.5))));
	} else {
		tmp = sin(th) * (sin(ky) / sqrt((0.5 * (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 <= 5e-311)
		tmp = sin(th);
	elseif (t_1 <= 5e-12)
		tmp = Float64(sin(th) * Float64(sin(ky) / sqrt(fma(kx, kx, fma(cos(Float64(ky + ky)), -0.5, 0.5)))));
	else
		tmp = Float64(sin(th) * Float64(sin(ky) / sqrt(Float64(0.5 * 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, 5e-311], N[Sin[th], $MachinePrecision], If[LessEqual[t$95$1, 5e-12], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $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[(0.5 * 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 5 \cdot 10^{-311}:\\
\;\;\;\;\sin th\\

\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{-12}:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\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 \frac{\sin ky}{\sqrt{0.5 \cdot \left(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)) < 5.00000000000023e-311

    1. Initial program 78.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.f6454.4

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

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

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

    1. Initial program 99.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-*.f6499.9

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

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

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

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

    1. Initial program 99.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{0.5 \cdot \left(1 - \cos \left(kx \cdot -2\right)\right)}}} \cdot \sin th \]
  3. Recombined 3 regimes into one program.
  4. Final simplification67.7%

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

Alternative 13: 44.6% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 7 \cdot 10^{-8}:\\ \;\;\;\;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)))) 7e-8)
   (* 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)))) <= 7e-8) {
		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)))) <= 7d-8) 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)))) <= 7e-8) {
		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)))) <= 7e-8:
		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)))) <= 7e-8)
		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)))) <= 7e-8)
		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], 7e-8], 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 7 \cdot 10^{-8}:\\
\;\;\;\;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))))) < 7.00000000000000048e-8

    1. Initial program 95.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. associate-+l+N/A

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

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

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

        \[\leadsto ky \cdot \color{blue}{\mathsf{fma}\left(ky, ky \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) + \frac{\sin th}{\sin kx}\right)} \]
    5. Applied rewrites30.7%

      \[\leadsto \color{blue}{ky \cdot \mathsf{fma}\left(ky, \frac{ky \cdot \left(-0.5 \cdot \sin th\right)}{{\sin kx}^{3}}, \mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot \frac{\sin th}{\sin kx}\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. Applied rewrites35.0%

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

    if 7.00000000000000048e-8 < (/.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.8%

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

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

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

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

Alternative 14: 99.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;{\sin kx}^{2} \leq 4 \cdot 10^{-14}:\\ \;\;\;\;\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(kx + kx\right), 0.5, 0.5 + -0.5 \cdot \cos \left(ky + ky\right)\right)}}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (pow (sin kx) 2.0) 4e-14)
   (* (sin th) (/ (sin ky) (hypot (sin ky) kx)))
   (*
    (sin th)
    (/
     (sin ky)
     (sqrt
      (fma (- 1.0 (cos (+ kx kx))) 0.5 (+ 0.5 (* -0.5 (cos (+ ky ky))))))))))
double code(double kx, double ky, double th) {
	double tmp;
	if (pow(sin(kx), 2.0) <= 4e-14) {
		tmp = sin(th) * (sin(ky) / hypot(sin(ky), kx));
	} else {
		tmp = sin(th) * (sin(ky) / sqrt(fma((1.0 - cos((kx + kx))), 0.5, (0.5 + (-0.5 * cos((ky + ky)))))));
	}
	return tmp;
}
function code(kx, ky, th)
	tmp = 0.0
	if ((sin(kx) ^ 2.0) <= 4e-14)
		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(kx + kx))), 0.5, Float64(0.5 + Float64(-0.5 * cos(Float64(ky + ky))))))));
	end
	return tmp
end
code[kx_, ky_, th_] := If[LessEqual[N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision], 4e-14], 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[(kx + kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 0.5 + N[(0.5 + N[(-0.5 * N[Cos[N[(ky + ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;{\sin kx}^{2} \leq 4 \cdot 10^{-14}:\\
\;\;\;\;\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(kx + kx\right), 0.5, 0.5 + -0.5 \cdot \cos \left(ky + ky\right)\right)}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) < 4e-14

    1. Initial program 90.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 \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-*.f6490.6

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

      \[\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.9

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

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

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

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, 0.5 + -0.5 \cdot \cos \left(ky + ky\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 4 \cdot 10^{-14}:\\ \;\;\;\;\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(kx + kx\right), 0.5, 0.5 + -0.5 \cdot \cos \left(ky + ky\right)\right)}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 15: 99.3% accurate, 1.0× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\frac{\sin ky \cdot \sin th}{\sqrt{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, \mathsf{fma}\left(\cos \left(ky + ky\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)) < 4.9999999999999997e-12

    1. Initial program 90.7%

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

      \[\leadsto \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-*.f6490.7

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
    5. Applied rewrites90.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.9

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

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

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

    1. Initial program 99.3%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Applied rewrites99.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 16: 15.4% 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 10^{-316}:\\ \;\;\;\;th \cdot \left(-0.16666666666666666 \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)))))
      1e-316)
   (* th (* -0.16666666666666666 (* 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))))) <= 1e-316) {
		tmp = th * (-0.16666666666666666 * (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))))) <= 1d-316) then
        tmp = th * ((-0.16666666666666666d0) * (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))))) <= 1e-316) {
		tmp = th * (-0.16666666666666666 * (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))))) <= 1e-316:
		tmp = th * (-0.16666666666666666 * (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))))) <= 1e-316)
		tmp = Float64(th * Float64(-0.16666666666666666 * 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))))) <= 1e-316)
		tmp = th * (-0.16666666666666666 * (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], 1e-316], N[(th * N[(-0.16666666666666666 * 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 10^{-316}:\\
\;\;\;\;th \cdot \left(-0.16666666666666666 \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)) < 9.999999837e-317

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

        \[\leadsto \color{blue}{\sin th} \]
    5. Applied rewrites20.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-*.f6413.1

        \[\leadsto th \cdot \mathsf{fma}\left(-0.16666666666666666, \color{blue}{th \cdot th}, 1\right) \]
    8. Applied rewrites13.1%

      \[\leadsto \color{blue}{th \cdot \mathsf{fma}\left(-0.16666666666666666, th \cdot th, 1\right)} \]
    9. Taylor expanded in th around inf

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

        \[\leadsto th \cdot \color{blue}{\left(\frac{-1}{6} \cdot {th}^{2}\right)} \]
      2. unpow2N/A

        \[\leadsto th \cdot \left(\frac{-1}{6} \cdot \color{blue}{\left(th \cdot th\right)}\right) \]
      3. lower-*.f6421.3

        \[\leadsto th \cdot \left(-0.16666666666666666 \cdot \color{blue}{\left(th \cdot th\right)}\right) \]
    11. Applied rewrites21.3%

      \[\leadsto th \cdot \color{blue}{\left(-0.16666666666666666 \cdot \left(th \cdot th\right)\right)} \]

    if 9.999999837e-317 < (*.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 93.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.f6426.1

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

      \[\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.9

        \[\leadsto th \cdot \mathsf{fma}\left(-0.16666666666666666, \color{blue}{th \cdot th}, 1\right) \]
    8. Applied rewrites13.9%

      \[\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. Applied rewrites14.4%

        \[\leadsto th \cdot \color{blue}{1} \]
      2. Step-by-step derivation
        1. *-rgt-identity14.4

          \[\leadsto \color{blue}{th} \]
      3. Applied rewrites14.4%

        \[\leadsto \color{blue}{th} \]
    11. Recombined 2 regimes into one program.
    12. Final simplification18.6%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\sin th \cdot \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 10^{-316}:\\ \;\;\;\;th \cdot \left(-0.16666666666666666 \cdot \left(th \cdot th\right)\right)\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \]
    13. Add Preprocessing

    Alternative 17: 15.4% 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 10^{-316}:\\ \;\;\;\;-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)))))
          1e-316)
       (* -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))))) <= 1e-316) {
    		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))))) <= 1d-316) 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))))) <= 1e-316) {
    		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))))) <= 1e-316:
    		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))))) <= 1e-316)
    		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))))) <= 1e-316)
    		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], 1e-316], 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 10^{-316}:\\
    \;\;\;\;-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)) < 9.999999837e-317

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

          \[\leadsto \color{blue}{\sin th} \]
      5. Applied rewrites20.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-*.f6413.1

          \[\leadsto th \cdot \mathsf{fma}\left(-0.16666666666666666, \color{blue}{th \cdot th}, 1\right) \]
      8. Applied rewrites13.1%

        \[\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-*.f6421.3

          \[\leadsto -0.16666666666666666 \cdot \left(th \cdot \color{blue}{\left(th \cdot th\right)}\right) \]
      11. Applied rewrites21.3%

        \[\leadsto \color{blue}{-0.16666666666666666 \cdot \left(th \cdot \left(th \cdot th\right)\right)} \]

      if 9.999999837e-317 < (*.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 93.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.f6426.1

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

        \[\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.9

          \[\leadsto th \cdot \mathsf{fma}\left(-0.16666666666666666, \color{blue}{th \cdot th}, 1\right) \]
      8. Applied rewrites13.9%

        \[\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. Applied rewrites14.4%

          \[\leadsto th \cdot \color{blue}{1} \]
        2. Step-by-step derivation
          1. *-rgt-identity14.4

            \[\leadsto \color{blue}{th} \]
        3. Applied rewrites14.4%

          \[\leadsto \color{blue}{th} \]
      11. Recombined 2 regimes into one program.
      12. Final simplification18.6%

        \[\leadsto \begin{array}{l} \mathbf{if}\;\sin th \cdot \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 10^{-316}:\\ \;\;\;\;-0.16666666666666666 \cdot \left(th \cdot \left(th \cdot th\right)\right)\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \]
      13. Add Preprocessing

      Alternative 18: 35.7% accurate, 1.0× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 10^{-11}:\\ \;\;\;\;\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)))) 1e-11)
         (* (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)))) <= 1e-11) {
      		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)))) <= 1d-11) 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)))) <= 1e-11) {
      		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)))) <= 1e-11:
      		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)))) <= 1e-11)
      		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)))) <= 1e-11)
      		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], 1e-11], 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 10^{-11}:\\
      \;\;\;\;\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))))) < 9.99999999999999939e-12

        1. Initial program 95.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-*.f6451.5

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

          \[\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-/.f6425.5

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

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

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

        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.f6466.9

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

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

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

      Alternative 19: 35.7% accurate, 1.0× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 7 \cdot 10^{-8}:\\ \;\;\;\;ky \cdot \frac{th}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
      (FPCore (kx ky th)
       :precision binary64
       (if (<= (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) 7e-8)
         (* ky (/ th (sin kx)))
         (sin th)))
      double code(double kx, double ky, double th) {
      	double tmp;
      	if ((sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) <= 7e-8) {
      		tmp = ky * (th / sin(kx));
      	} else {
      		tmp = sin(th);
      	}
      	return tmp;
      }
      
      real(8) function code(kx, ky, th)
          real(8), intent (in) :: kx
          real(8), intent (in) :: ky
          real(8), intent (in) :: th
          real(8) :: tmp
          if ((sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) <= 7d-8) then
              tmp = ky * (th / sin(kx))
          else
              tmp = sin(th)
          end if
          code = tmp
      end function
      
      public static double code(double kx, double ky, double th) {
      	double tmp;
      	if ((Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) <= 7e-8) {
      		tmp = ky * (th / Math.sin(kx));
      	} else {
      		tmp = Math.sin(th);
      	}
      	return tmp;
      }
      
      def code(kx, ky, th):
      	tmp = 0
      	if (math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))) <= 7e-8:
      		tmp = ky * (th / math.sin(kx))
      	else:
      		tmp = math.sin(th)
      	return tmp
      
      function code(kx, ky, th)
      	tmp = 0.0
      	if (Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 7e-8)
      		tmp = Float64(ky * Float64(th / sin(kx)));
      	else
      		tmp = sin(th);
      	end
      	return tmp
      end
      
      function tmp_2 = code(kx, ky, th)
      	tmp = 0.0;
      	if ((sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 7e-8)
      		tmp = ky * (th / sin(kx));
      	else
      		tmp = sin(th);
      	end
      	tmp_2 = tmp;
      end
      
      code[kx_, ky_, th_] := If[LessEqual[N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 7e-8], N[(ky * N[(th / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 7 \cdot 10^{-8}:\\
      \;\;\;\;ky \cdot \frac{th}{\sin kx}\\
      
      \mathbf{else}:\\
      \;\;\;\;\sin th\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 7.00000000000000048e-8

        1. Initial program 95.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}{\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.f6432.8

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

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

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

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

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

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

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

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

        if 7.00000000000000048e-8 < (/.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.8%

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

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

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

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

      Alternative 20: 31.1% accurate, 1.0× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 2 \cdot 10^{-42}:\\ \;\;\;\;0.16666666666666666 \cdot \left(kx \cdot \left(ky \cdot \sin 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)))) 2e-42)
         (* 0.16666666666666666 (* kx (* ky (sin th))))
         (sin th)))
      double code(double kx, double ky, double th) {
      	double tmp;
      	if ((sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) <= 2e-42) {
      		tmp = 0.16666666666666666 * (kx * (ky * sin(th)));
      	} else {
      		tmp = sin(th);
      	}
      	return tmp;
      }
      
      real(8) function code(kx, ky, th)
          real(8), intent (in) :: kx
          real(8), intent (in) :: ky
          real(8), intent (in) :: th
          real(8) :: tmp
          if ((sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) <= 2d-42) then
              tmp = 0.16666666666666666d0 * (kx * (ky * sin(th)))
          else
              tmp = sin(th)
          end if
          code = tmp
      end function
      
      public static double code(double kx, double ky, double th) {
      	double tmp;
      	if ((Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) <= 2e-42) {
      		tmp = 0.16666666666666666 * (kx * (ky * Math.sin(th)));
      	} else {
      		tmp = Math.sin(th);
      	}
      	return tmp;
      }
      
      def code(kx, ky, th):
      	tmp = 0
      	if (math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))) <= 2e-42:
      		tmp = 0.16666666666666666 * (kx * (ky * math.sin(th)))
      	else:
      		tmp = math.sin(th)
      	return tmp
      
      function code(kx, ky, th)
      	tmp = 0.0
      	if (Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 2e-42)
      		tmp = Float64(0.16666666666666666 * Float64(kx * Float64(ky * sin(th))));
      	else
      		tmp = sin(th);
      	end
      	return tmp
      end
      
      function tmp_2 = code(kx, ky, th)
      	tmp = 0.0;
      	if ((sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 2e-42)
      		tmp = 0.16666666666666666 * (kx * (ky * sin(th)));
      	else
      		tmp = sin(th);
      	end
      	tmp_2 = tmp;
      end
      
      code[kx_, ky_, th_] := If[LessEqual[N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2e-42], N[(0.16666666666666666 * N[(kx * N[(ky * N[Sin[th], $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 2 \cdot 10^{-42}:\\
      \;\;\;\;0.16666666666666666 \cdot \left(kx \cdot \left(ky \cdot \sin 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))))) < 2.00000000000000008e-42

        1. Initial program 95.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}{\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.f6432.8

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(0.16666666666666666, kx \cdot kx, 1\right) \cdot \left(ky \cdot \sin th\right)}{kx}} \]
        9. Taylor expanded in kx around inf

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

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

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

            \[\leadsto \frac{1}{6} \cdot \left(kx \cdot \color{blue}{\left(ky \cdot \sin th\right)}\right) \]
          4. lower-sin.f6419.3

            \[\leadsto 0.16666666666666666 \cdot \left(kx \cdot \left(ky \cdot \color{blue}{\sin th}\right)\right) \]
        11. Applied rewrites19.3%

          \[\leadsto \color{blue}{0.16666666666666666 \cdot \left(kx \cdot \left(ky \cdot \sin th\right)\right)} \]

        if 2.00000000000000008e-42 < (/.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 94.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.f6465.4

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

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

      Alternative 21: 30.7% accurate, 1.0× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 2 \cdot 10^{-63}:\\ \;\;\;\;th \cdot \left(-0.16666666666666666 \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)))) 2e-63)
         (* th (* -0.16666666666666666 (* 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)))) <= 2e-63) {
      		tmp = th * (-0.16666666666666666 * (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)))) <= 2d-63) then
              tmp = th * ((-0.16666666666666666d0) * (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)))) <= 2e-63) {
      		tmp = th * (-0.16666666666666666 * (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)))) <= 2e-63:
      		tmp = th * (-0.16666666666666666 * (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)))) <= 2e-63)
      		tmp = Float64(th * Float64(-0.16666666666666666 * 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)))) <= 2e-63)
      		tmp = th * (-0.16666666666666666 * (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], 2e-63], N[(th * N[(-0.16666666666666666 * 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 2 \cdot 10^{-63}:\\
      \;\;\;\;th \cdot \left(-0.16666666666666666 \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))))) < 2.00000000000000013e-63

        1. Initial program 95.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.6

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

          \[\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. Applied rewrites3.4%

          \[\leadsto \color{blue}{th \cdot \mathsf{fma}\left(-0.16666666666666666, th \cdot th, 1\right)} \]
        9. Taylor expanded in th around inf

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

            \[\leadsto th \cdot \color{blue}{\left(\frac{-1}{6} \cdot {th}^{2}\right)} \]
          2. unpow2N/A

            \[\leadsto th \cdot \left(\frac{-1}{6} \cdot \color{blue}{\left(th \cdot th\right)}\right) \]
          3. lower-*.f6418.8

            \[\leadsto th \cdot \left(-0.16666666666666666 \cdot \color{blue}{\left(th \cdot th\right)}\right) \]
        11. Applied rewrites18.8%

          \[\leadsto th \cdot \color{blue}{\left(-0.16666666666666666 \cdot \left(th \cdot th\right)\right)} \]

        if 2.00000000000000013e-63 < (/.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 94.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.f6464.0

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

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

      Alternative 22: 67.2% accurate, 1.8× speedup?

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

        1. Initial program 93.8%

          \[\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 rewrites99.6%

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

          \[\leadsto \frac{\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-*.f6470.2

            \[\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. Applied rewrites70.2%

          \[\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 \]
        8. Taylor expanded in ky around 0

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

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

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

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

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

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

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

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

        if 2.10000000000000009 < ky

        1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      Alternative 23: 13.7% accurate, 632.0× speedup?

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

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

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

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

        \[\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.4

          \[\leadsto th \cdot \mathsf{fma}\left(-0.16666666666666666, \color{blue}{th \cdot th}, 1\right) \]
      8. Applied rewrites13.4%

        \[\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. Applied rewrites13.8%

          \[\leadsto th \cdot \color{blue}{1} \]
        2. Step-by-step derivation
          1. *-rgt-identity13.8

            \[\leadsto \color{blue}{th} \]
        3. Applied rewrites13.8%

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

        Reproduce

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