Toniolo and Linder, Equation (3b), real

Percentage Accurate: 94.4% → 99.7%
Time: 11.8s
Alternatives: 26
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 26 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.4% 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 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 egg-rr99.6%

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

Alternative 2: 79.1% accurate, 0.2× speedup?

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

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

\mathbf{elif}\;t\_3 \leq -0.04:\\
\;\;\;\;\left(\sin ky \cdot th\right) \cdot t\_5\\

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

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

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

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


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

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

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

        \[\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 egg-rr59.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 kx around 0

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)}}} \cdot \sin th \]
      2. +-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 \]
      3. 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 \]
      4. 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 \]
      5. 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 \]
      6. 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 \]
      7. 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 \]
      8. *-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 \]
      9. lower-*.f6452.3

        \[\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. Simplified52.3%

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

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

    1. Initial program 99.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.0400000000000000008 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 0.20000000000000001 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. Taylor expanded in ky around 0

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

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

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

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

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

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

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

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

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

    1. Initial program 99.5%

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

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

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

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

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

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 64.2% accurate, 0.2× speedup?

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

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

\mathbf{elif}\;t\_2 \leq -0.2:\\
\;\;\;\;\left(\sin ky \cdot th\right) \cdot t\_4\\

\mathbf{elif}\;t\_2 \leq 0.2:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\

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

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

\mathbf{else}:\\
\;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\


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

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

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

        \[\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 egg-rr59.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 kx around 0

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)}}} \cdot \sin th \]
      2. +-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 \]
      3. 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 \]
      4. 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 \]
      5. 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 \]
      6. 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 \]
      7. 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 \]
      8. *-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 \]
      9. lower-*.f6452.3

        \[\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. Simplified52.3%

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

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

    1. Initial program 99.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.4%

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

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

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

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

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

    1. Initial program 99.5%

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

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

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

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

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

    1. Initial program 98.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 2.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 egg-rr99.6%

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

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

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

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

      \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]
  3. Recombined 6 regimes into one program.
  4. Final simplification64.8%

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

Alternative 4: 64.2% accurate, 0.2× speedup?

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

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

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

\mathbf{elif}\;t\_2 \leq 0.2:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\

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

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

\mathbf{else}:\\
\;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\


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

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

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

        \[\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 egg-rr59.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 kx around 0

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)}}} \cdot \sin th \]
      2. +-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 \]
      3. 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 \]
      4. 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 \]
      5. 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 \]
      6. 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 \]
      7. 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 \]
      8. *-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 \]
      9. lower-*.f6452.3

        \[\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. Simplified52.3%

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

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

    1. Initial program 99.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.4%

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

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

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

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

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

    1. Initial program 99.5%

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

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

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

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

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

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

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

        \[\leadsto \left(\sin ky \cdot \mathsf{fma}\left(th, \frac{-1}{6} \cdot \color{blue}{\left(th \cdot th\right)}, th\right)\right) \cdot \sqrt{\frac{1}{\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-*.f6441.0

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

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

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

    1. Initial program 98.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 2.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 egg-rr99.6%

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

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

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

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

      \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]
  3. Recombined 6 regimes into one program.
  4. Final simplification64.8%

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

Alternative 5: 64.4% accurate, 0.2× speedup?

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

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

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

\mathbf{elif}\;t\_3 \leq 0.05:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\

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

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

\mathbf{else}:\\
\;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\


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

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

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

        \[\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 egg-rr59.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 kx around 0

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)}}} \cdot \sin th \]
      2. +-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 \]
      3. 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 \]
      4. 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 \]
      5. 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 \]
      6. 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 \]
      7. 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 \]
      8. *-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 \]
      9. lower-*.f6452.3

        \[\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. Simplified52.3%

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

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

    1. Initial program 99.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.4%

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

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

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

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

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

    1. Initial program 98.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 2.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 egg-rr99.6%

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

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

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

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

      \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]
  3. Recombined 5 regimes into one program.
  4. Final simplification64.8%

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

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

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

\mathbf{elif}\;t\_1 \leq -0.04:\\
\;\;\;\;\left(\sin ky \cdot th\right) \cdot t\_3\\

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

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

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


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

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

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

        \[\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 egg-rr59.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 kx around 0

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)}}} \cdot \sin th \]
      2. +-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 \]
      3. 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 \]
      4. 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 \]
      5. 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 \]
      6. 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 \]
      7. 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 \]
      8. *-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 \]
      9. lower-*.f6452.3

        \[\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. Simplified52.3%

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

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

    1. Initial program 99.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.5%

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

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

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

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

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

    1. Initial program 89.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.f64100.0

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -0.98:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\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 -0.04:\\ \;\;\;\;\left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(0.5, 1 - \cos \left(kx \cdot -2\right), \mathsf{fma}\left(-0.5, \cos \left(ky \cdot -2\right), 0.5\right)\right)}}\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.2:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin kx, ky\right)}\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.99996:\\ \;\;\;\;th \cdot \left(\sqrt{\frac{1}{\mathsf{fma}\left(0.5, 1 - \cos \left(kx \cdot -2\right), \mathsf{fma}\left(-0.5, \cos \left(ky \cdot -2\right), 0.5\right)\right)}} \cdot \left(\sin ky \cdot \mathsf{fma}\left(-0.16666666666666666, th \cdot th, 1\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \mathsf{fma}\left(kx, -0.16666666666666666 \cdot \left(kx \cdot kx\right), kx\right)\right)}\\ \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.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 1.5 \cdot 10^{-223}:\\ \;\;\;\;\sin th \cdot \left(\sin ky \cdot \sqrt{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}\right)\\ \mathbf{elif}\;t\_1 \leq 0.05:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\ \mathbf{elif}\;t\_1 \leq 2:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \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 1.5e-223)
       (* (sin th) (* (sin ky) (sqrt (/ 2.0 (- 1.0 (cos (* kx -2.0)))))))
       (if (<= t_1 0.05)
         (* (sin th) (/ (sin ky) (sin kx)))
         (if (<= t_1 2.0) (sin th) (* (sin th) (/ ky (sin kx)))))))))
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 <= 1.5e-223) {
		tmp = sin(th) * (sin(ky) * sqrt((2.0 / (1.0 - cos((kx * -2.0))))));
	} else if (t_1 <= 0.05) {
		tmp = sin(th) * (sin(ky) / sin(kx));
	} else if (t_1 <= 2.0) {
		tmp = sin(th);
	} else {
		tmp = sin(th) * (ky / sin(kx));
	}
	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 <= 1.5e-223)
		tmp = Float64(sin(th) * Float64(sin(ky) * sqrt(Float64(2.0 / Float64(1.0 - cos(Float64(kx * -2.0)))))));
	elseif (t_1 <= 0.05)
		tmp = Float64(sin(th) * Float64(sin(ky) / sin(kx)));
	elseif (t_1 <= 2.0)
		tmp = sin(th);
	else
		tmp = Float64(sin(th) * Float64(ky / sin(kx)));
	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, 1.5e-223], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] * N[Sqrt[N[(2.0 / N[(1.0 - N[Cos[N[(kx * -2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 0.05], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2.0], N[Sin[th], $MachinePrecision], N[(N[Sin[th], $MachinePrecision] * N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $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 1.5 \cdot 10^{-223}:\\
\;\;\;\;\sin th \cdot \left(\sin ky \cdot \sqrt{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}\right)\\

\mathbf{elif}\;t\_1 \leq 0.05:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\

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

\mathbf{else}:\\
\;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\


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

    1. Initial program 85.0%

      \[\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.f6485.0

        \[\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 egg-rr69.7%

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)}}} \cdot \sin th \]
      2. +-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 \]
      3. 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 \]
      4. 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 \]
      5. 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 \]
      6. 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 \]
      7. 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 \]
      8. *-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 \]
      9. lower-*.f6444.4

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\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))))) < 1.49999999999999996e-223

    1. Initial program 99.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.6%

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

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

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

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

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

    1. Initial program 98.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.f6466.4

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

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

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

    1. Initial program 2.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 egg-rr99.6%

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

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

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

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

      \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]
  3. Recombined 5 regimes into one program.
  4. Final simplification57.2%

    \[\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 1.5 \cdot 10^{-223}:\\ \;\;\;\;\sin th \cdot \left(\sin ky \cdot \sqrt{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}\right)\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.05:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 2:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 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.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 1.5 \cdot 10^{-223}:\\ \;\;\;\;\sin ky \cdot \left(\sin th \cdot \sqrt{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}\right)\\ \mathbf{elif}\;t\_1 \leq 0.05:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\ \mathbf{elif}\;t\_1 \leq 2:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \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 1.5e-223)
       (* (sin ky) (* (sin th) (sqrt (/ 2.0 (- 1.0 (cos (* kx -2.0)))))))
       (if (<= t_1 0.05)
         (* (sin th) (/ (sin ky) (sin kx)))
         (if (<= t_1 2.0) (sin th) (* (sin th) (/ ky (sin kx)))))))))
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 <= 1.5e-223) {
		tmp = sin(ky) * (sin(th) * sqrt((2.0 / (1.0 - cos((kx * -2.0))))));
	} else if (t_1 <= 0.05) {
		tmp = sin(th) * (sin(ky) / sin(kx));
	} else if (t_1 <= 2.0) {
		tmp = sin(th);
	} else {
		tmp = sin(th) * (ky / sin(kx));
	}
	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 <= 1.5e-223)
		tmp = Float64(sin(ky) * Float64(sin(th) * sqrt(Float64(2.0 / Float64(1.0 - cos(Float64(kx * -2.0)))))));
	elseif (t_1 <= 0.05)
		tmp = Float64(sin(th) * Float64(sin(ky) / sin(kx)));
	elseif (t_1 <= 2.0)
		tmp = sin(th);
	else
		tmp = Float64(sin(th) * Float64(ky / sin(kx)));
	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, 1.5e-223], N[(N[Sin[ky], $MachinePrecision] * N[(N[Sin[th], $MachinePrecision] * N[Sqrt[N[(2.0 / N[(1.0 - N[Cos[N[(kx * -2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 0.05], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2.0], N[Sin[th], $MachinePrecision], N[(N[Sin[th], $MachinePrecision] * N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $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 1.5 \cdot 10^{-223}:\\
\;\;\;\;\sin ky \cdot \left(\sin th \cdot \sqrt{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}\right)\\

\mathbf{elif}\;t\_1 \leq 0.05:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\

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

\mathbf{else}:\\
\;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\


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

    1. Initial program 85.0%

      \[\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.f6485.0

        \[\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 egg-rr69.7%

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)}}} \cdot \sin th \]
      2. +-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 \]
      3. 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 \]
      4. 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 \]
      5. 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 \]
      6. 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 \]
      7. 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 \]
      8. *-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 \]
      9. lower-*.f6444.4

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\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))))) < 1.49999999999999996e-223

    1. Initial program 99.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.6%

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

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

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

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

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

    1. Initial program 98.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.f6466.4

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

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

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

    1. Initial program 2.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 egg-rr99.6%

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

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

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

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

      \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]
  3. Recombined 5 regimes into one program.
  4. Final simplification57.2%

    \[\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 1.5 \cdot 10^{-223}:\\ \;\;\;\;\sin ky \cdot \left(\sin th \cdot \sqrt{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}\right)\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.05:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 2:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 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.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 1.5 \cdot 10^{-223}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\sqrt{0.5 \cdot \left(1 - \cos \left(kx \cdot -2\right)\right)}}\\ \mathbf{elif}\;t\_1 \leq 0.05:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\ \mathbf{elif}\;t\_1 \leq 2:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \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 1.5e-223)
       (* (sin ky) (/ (sin th) (sqrt (* 0.5 (- 1.0 (cos (* kx -2.0)))))))
       (if (<= t_1 0.05)
         (* (sin th) (/ (sin ky) (sin kx)))
         (if (<= t_1 2.0) (sin th) (* (sin th) (/ ky (sin kx)))))))))
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 <= 1.5e-223) {
		tmp = sin(ky) * (sin(th) / sqrt((0.5 * (1.0 - cos((kx * -2.0))))));
	} else if (t_1 <= 0.05) {
		tmp = sin(th) * (sin(ky) / sin(kx));
	} else if (t_1 <= 2.0) {
		tmp = sin(th);
	} else {
		tmp = sin(th) * (ky / sin(kx));
	}
	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 <= 1.5e-223)
		tmp = Float64(sin(ky) * Float64(sin(th) / sqrt(Float64(0.5 * Float64(1.0 - cos(Float64(kx * -2.0)))))));
	elseif (t_1 <= 0.05)
		tmp = Float64(sin(th) * Float64(sin(ky) / sin(kx)));
	elseif (t_1 <= 2.0)
		tmp = sin(th);
	else
		tmp = Float64(sin(th) * Float64(ky / sin(kx)));
	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, 1.5e-223], N[(N[Sin[ky], $MachinePrecision] * N[(N[Sin[th], $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, 0.05], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2.0], N[Sin[th], $MachinePrecision], N[(N[Sin[th], $MachinePrecision] * N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $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 1.5 \cdot 10^{-223}:\\
\;\;\;\;\sin ky \cdot \frac{\sin th}{\sqrt{0.5 \cdot \left(1 - \cos \left(kx \cdot -2\right)\right)}}\\

\mathbf{elif}\;t\_1 \leq 0.05:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\

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

\mathbf{else}:\\
\;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\


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

    1. Initial program 85.0%

      \[\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.f6485.0

        \[\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 egg-rr69.7%

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)}}} \cdot \sin th \]
      2. +-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 \]
      3. 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 \]
      4. 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 \]
      5. 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 \]
      6. 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 \]
      7. 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 \]
      8. *-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 \]
      9. lower-*.f6444.4

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\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))))) < 1.49999999999999996e-223

    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 egg-rr76.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}{\color{blue}{\sqrt{\frac{1}{2}} \cdot \sqrt{1 - \cos \left(2 \cdot kx\right)}}} \cdot \sin th \]
    6. Step-by-step derivation
      1. lower-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.6%

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

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

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

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

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

    1. Initial program 98.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.f6466.4

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

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

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

    1. Initial program 2.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 egg-rr99.6%

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

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

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

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

      \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]
  3. Recombined 5 regimes into one program.
  4. Final simplification57.2%

    \[\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 1.5 \cdot 10^{-223}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\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 0.05:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 2:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 57.8% 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.1:\\ \;\;\;\;\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 0.05:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\ \mathbf{elif}\;t\_1 \leq 2:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \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.1)
     (* (sin th) (/ (sin ky) (sqrt (fma -0.5 (cos (* ky -2.0)) 0.5))))
     (if (<= t_1 0.05)
       (* (sin th) (/ (sin ky) (sin kx)))
       (if (<= t_1 2.0) (sin th) (* (sin th) (/ ky (sin kx))))))))
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.1) {
		tmp = sin(th) * (sin(ky) / sqrt(fma(-0.5, cos((ky * -2.0)), 0.5)));
	} else if (t_1 <= 0.05) {
		tmp = sin(th) * (sin(ky) / sin(kx));
	} else if (t_1 <= 2.0) {
		tmp = sin(th);
	} else {
		tmp = sin(th) * (ky / sin(kx));
	}
	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.1)
		tmp = Float64(sin(th) * Float64(sin(ky) / sqrt(fma(-0.5, cos(Float64(ky * -2.0)), 0.5))));
	elseif (t_1 <= 0.05)
		tmp = Float64(sin(th) * Float64(sin(ky) / sin(kx)));
	elseif (t_1 <= 2.0)
		tmp = sin(th);
	else
		tmp = Float64(sin(th) * Float64(ky / sin(kx)));
	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.1], 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, 0.05], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2.0], N[Sin[th], $MachinePrecision], N[(N[Sin[th], $MachinePrecision] * N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $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.1:\\
\;\;\;\;\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 0.05:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\

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

\mathbf{else}:\\
\;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\


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

    1. Initial program 88.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.f6488.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 egg-rr76.4%

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)}}} \cdot \sin th \]
      2. +-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 \]
      3. 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 \]
      4. 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 \]
      5. 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 \]
      6. 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 \]
      7. 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 \]
      8. *-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 \]
      9. lower-*.f6438.5

        \[\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. Simplified38.5%

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

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

    1. Initial program 99.4%

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

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

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

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

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

    1. Initial program 98.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.f6466.4

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

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

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

    1. Initial program 2.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 egg-rr99.6%

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

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

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

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

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

    \[\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}{\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 0.05:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 2:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 44.2% accurate, 0.5× speedup?

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

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

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

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


\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.0100000000000000002 or 2 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

    1. Initial program 92.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 98.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.f6464.8

        \[\leadsto \color{blue}{\sin th} \]
    5. Simplified64.8%

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

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

Alternative 12: 35.6% accurate, 0.5× speedup?

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

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

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

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


\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.0100000000000000002 or 2 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

    1. Initial program 92.0%

      \[\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.f6492.0

        \[\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 egg-rr68.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sin th \cdot \frac{\color{blue}{\sin ky}}{kx} \]
    10. Simplified25.7%

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

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

    1. Initial program 98.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.f6464.8

        \[\leadsto \color{blue}{\sin th} \]
    5. Simplified64.8%

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

Alternative 13: 35.5% accurate, 0.5× speedup?

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

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

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

\mathbf{else}:\\
\;\;\;\;t\_1 \cdot \left(ky \cdot \frac{\mathsf{fma}\left(0.08333333333333333, \frac{kx \cdot kx}{\sqrt{0.5}}, \sqrt{0.5}\right)}{kx}\right)\\


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

    1. Initial program 93.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 98.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.f6464.8

        \[\leadsto \color{blue}{\sin th} \]
    5. Simplified64.8%

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

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

    1. Initial program 2.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\frac{\mathsf{fma}\left(0.08333333333333333, \frac{kx \cdot kx}{\sqrt{0.5}}, \sqrt{0.5}\right)}{kx} \cdot ky\right) \cdot \color{blue}{\left(\sin th \cdot \sqrt{2}\right)} \]
    11. Applied egg-rr25.8%

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

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

Alternative 14: 35.5% accurate, 0.5× speedup?

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

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

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

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


\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.0100000000000000002 or 2 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

    1. Initial program 92.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 98.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.f6464.8

        \[\leadsto \color{blue}{\sin th} \]
    5. Simplified64.8%

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

Alternative 15: 34.6% accurate, 0.5× speedup?

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

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

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

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


\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.0100000000000000002 or 2 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

    1. Initial program 92.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 98.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.f6464.8

        \[\leadsto \color{blue}{\sin th} \]
    5. Simplified64.8%

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

Alternative 16: 33.7% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 10^{-10}:\\ \;\;\;\;th \cdot \left(\frac{\sin ky}{kx} \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\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)))) 1e-10)
   (* th (* (/ (sin ky) kx) (* (sqrt 0.5) (sqrt 2.0))))
   (sin th)))
double code(double kx, double ky, double th) {
	double tmp;
	if ((sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) <= 1e-10) {
		tmp = th * ((sin(ky) / kx) * (sqrt(0.5) * sqrt(2.0)));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if ((sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) <= 1d-10) then
        tmp = th * ((sin(ky) / kx) * (sqrt(0.5d0) * sqrt(2.0d0)))
    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-10) {
		tmp = th * ((Math.sin(ky) / kx) * (Math.sqrt(0.5) * Math.sqrt(2.0)));
	} 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-10:
		tmp = th * ((math.sin(ky) / kx) * (math.sqrt(0.5) * math.sqrt(2.0)))
	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-10)
		tmp = Float64(th * Float64(Float64(sin(ky) / kx) * Float64(sqrt(0.5) * sqrt(2.0))));
	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-10)
		tmp = th * ((sin(ky) / kx) * (sqrt(0.5) * sqrt(2.0)));
	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-10], N[(th * N[(N[(N[Sin[ky], $MachinePrecision] / kx), $MachinePrecision] * N[(N[Sqrt[0.5], $MachinePrecision] * N[Sqrt[2.0], $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 10^{-10}:\\
\;\;\;\;th \cdot \left(\frac{\sin ky}{kx} \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\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))))) < 1.00000000000000004e-10

    1. Initial program 93.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 93.4%

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

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

        \[\leadsto \color{blue}{\sin th} \]
    5. Simplified62.8%

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

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

Alternative 17: 15.1% 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 2 \cdot 10^{-283}:\\ \;\;\;\;-0.16666666666666666 \cdot \left(th \cdot \left(th \cdot th\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(th, \left(th \cdot th\right) \cdot \mathsf{fma}\left(0.008333333333333333, th \cdot th, -0.16666666666666666\right), th\right)\\ \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)))))
      2e-283)
   (* -0.16666666666666666 (* th (* th th)))
   (fma
    th
    (* (* th th) (fma 0.008333333333333333 (* th th) -0.16666666666666666))
    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))))) <= 2e-283) {
		tmp = -0.16666666666666666 * (th * (th * th));
	} else {
		tmp = fma(th, ((th * th) * fma(0.008333333333333333, (th * th), -0.16666666666666666)), 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))))) <= 2e-283)
		tmp = Float64(-0.16666666666666666 * Float64(th * Float64(th * th)));
	else
		tmp = fma(th, Float64(Float64(th * th) * fma(0.008333333333333333, Float64(th * th), -0.16666666666666666)), th);
	end
	return 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], 2e-283], N[(-0.16666666666666666 * N[(th * N[(th * th), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(th * N[(N[(th * th), $MachinePrecision] * N[(0.008333333333333333 * N[(th * th), $MachinePrecision] + -0.16666666666666666), $MachinePrecision]), $MachinePrecision] + th), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\sin th \cdot \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 2 \cdot 10^{-283}:\\
\;\;\;\;-0.16666666666666666 \cdot \left(th \cdot \left(th \cdot th\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(th, \left(th \cdot th\right) \cdot \mathsf{fma}\left(0.008333333333333333, th \cdot th, -0.16666666666666666\right), th\right)\\


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

    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.f6419.2

        \[\leadsto \color{blue}{\sin th} \]
    5. Simplified19.2%

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

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

        \[\leadsto \color{blue}{th \cdot \left(\frac{-1}{6} \cdot {th}^{2}\right) + th \cdot 1} \]
      3. *-rgt-identityN/A

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\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-*.f6416.7

        \[\leadsto -0.16666666666666666 \cdot \left(th \cdot \color{blue}{\left(th \cdot th\right)}\right) \]
    11. Simplified16.7%

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

    if 1.99999999999999989e-283 < (*.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 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 \color{blue}{\sin th} \]
    4. Step-by-step derivation
      1. lower-sin.f6420.9

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

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

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

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

        \[\leadsto \color{blue}{th \cdot \left({th}^{2} \cdot \left(\frac{1}{120} \cdot {th}^{2} - \frac{1}{6}\right)\right) + th \cdot 1} \]
      3. *-rgt-identityN/A

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(th, {th}^{2} \cdot \left(\frac{1}{120} \cdot {th}^{2} - \frac{1}{6}\right), th\right)} \]
      5. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(th, \color{blue}{{th}^{2} \cdot \left(\frac{1}{120} \cdot {th}^{2} - \frac{1}{6}\right)}, th\right) \]
      6. unpow2N/A

        \[\leadsto \mathsf{fma}\left(th, \color{blue}{\left(th \cdot th\right)} \cdot \left(\frac{1}{120} \cdot {th}^{2} - \frac{1}{6}\right), th\right) \]
      7. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(th, \color{blue}{\left(th \cdot th\right)} \cdot \left(\frac{1}{120} \cdot {th}^{2} - \frac{1}{6}\right), th\right) \]
      8. sub-negN/A

        \[\leadsto \mathsf{fma}\left(th, \left(th \cdot th\right) \cdot \color{blue}{\left(\frac{1}{120} \cdot {th}^{2} + \left(\mathsf{neg}\left(\frac{1}{6}\right)\right)\right)}, th\right) \]
      9. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(th, \left(th \cdot th\right) \cdot \left(\frac{1}{120} \cdot {th}^{2} + \color{blue}{\frac{-1}{6}}\right), th\right) \]
      10. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(th, \left(th \cdot th\right) \cdot \color{blue}{\mathsf{fma}\left(\frac{1}{120}, {th}^{2}, \frac{-1}{6}\right)}, th\right) \]
      11. unpow2N/A

        \[\leadsto \mathsf{fma}\left(th, \left(th \cdot th\right) \cdot \mathsf{fma}\left(\frac{1}{120}, \color{blue}{th \cdot th}, \frac{-1}{6}\right), th\right) \]
      12. lower-*.f6411.5

        \[\leadsto \mathsf{fma}\left(th, \left(th \cdot th\right) \cdot \mathsf{fma}\left(0.008333333333333333, \color{blue}{th \cdot th}, -0.16666666666666666\right), th\right) \]
    8. Simplified11.5%

      \[\leadsto \color{blue}{\mathsf{fma}\left(th, \left(th \cdot th\right) \cdot \mathsf{fma}\left(0.008333333333333333, th \cdot th, -0.16666666666666666\right), th\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification14.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin th \cdot \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 2 \cdot 10^{-283}:\\ \;\;\;\;-0.16666666666666666 \cdot \left(th \cdot \left(th \cdot th\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(th, \left(th \cdot th\right) \cdot \mathsf{fma}\left(0.008333333333333333, th \cdot th, -0.16666666666666666\right), th\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 18: 99.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;{\sin kx}^{2} \leq 5 \cdot 10^{-11}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \mathsf{fma}\left(kx, -0.16666666666666666 \cdot \left(kx \cdot kx\right), kx\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\sin ky \cdot \frac{\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)}}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (pow (sin kx) 2.0) 5e-11)
   (*
    (sin th)
    (/
     (sin ky)
     (hypot (sin ky) (fma kx (* -0.16666666666666666 (* kx kx)) kx))))
   (*
    (sin ky)
    (/
     (sin th)
     (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) <= 5e-11) {
		tmp = sin(th) * (sin(ky) / hypot(sin(ky), fma(kx, (-0.16666666666666666 * (kx * kx)), kx)));
	} else {
		tmp = sin(ky) * (sin(th) / 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) <= 5e-11)
		tmp = Float64(sin(th) * Float64(sin(ky) / hypot(sin(ky), fma(kx, Float64(-0.16666666666666666 * Float64(kx * kx)), kx))));
	else
		tmp = Float64(sin(ky) * Float64(sin(th) / 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], 5e-11], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[(kx * N[(-0.16666666666666666 * N[(kx * kx), $MachinePrecision]), $MachinePrecision] + kx), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[ky], $MachinePrecision] * N[(N[Sin[th], $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 5 \cdot 10^{-11}:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \mathsf{fma}\left(kx, -0.16666666666666666 \cdot \left(kx \cdot kx\right), kx\right)\right)}\\

\mathbf{else}:\\
\;\;\;\;\sin ky \cdot \frac{\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)}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) < 5.00000000000000018e-11

    1. Initial program 87.9%

      \[\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.9

        \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
    4. Applied egg-rr99.9%

      \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
    5. Taylor expanded in kx around 0

      \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{kx \cdot \left(1 + \frac{-1}{6} \cdot {kx}^{2}\right)}\right)} \cdot \sin th \]
    6. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx \cdot \color{blue}{\left(\frac{-1}{6} \cdot {kx}^{2} + 1\right)}\right)} \cdot \sin th \]
      2. distribute-lft-inN/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{kx \cdot \left(\frac{-1}{6} \cdot {kx}^{2}\right) + kx \cdot 1}\right)} \cdot \sin th \]
      3. *-rgt-identityN/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx \cdot \left(\frac{-1}{6} \cdot {kx}^{2}\right) + \color{blue}{kx}\right)} \cdot \sin th \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{\mathsf{fma}\left(kx, \frac{-1}{6} \cdot {kx}^{2}, kx\right)}\right)} \cdot \sin th \]
      5. lower-*.f64N/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \mathsf{fma}\left(kx, \color{blue}{\frac{-1}{6} \cdot {kx}^{2}}, kx\right)\right)} \cdot \sin th \]
      6. unpow2N/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \mathsf{fma}\left(kx, \frac{-1}{6} \cdot \color{blue}{\left(kx \cdot kx\right)}, kx\right)\right)} \cdot \sin th \]
      7. lower-*.f6499.9

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \mathsf{fma}\left(kx, -0.16666666666666666 \cdot \color{blue}{\left(kx \cdot kx\right)}, kx\right)\right)} \cdot \sin th \]
    7. Simplified99.9%

      \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{\mathsf{fma}\left(kx, -0.16666666666666666 \cdot \left(kx \cdot kx\right), kx\right)}\right)} \cdot \sin th \]

    if 5.00000000000000018e-11 < (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 egg-rr99.2%

      \[\leadsto \color{blue}{\frac{\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)}} \cdot \sin ky} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;{\sin kx}^{2} \leq 5 \cdot 10^{-11}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \mathsf{fma}\left(kx, -0.16666666666666666 \cdot \left(kx \cdot kx\right), kx\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\sin ky \cdot \frac{\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)}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 19: 99.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;{\sin kx}^{2} \leq 5 \cdot 10^{-11}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \mathsf{fma}\left(kx, -0.16666666666666666 \cdot \left(kx \cdot kx\right), kx\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\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-11)
   (*
    (sin th)
    (/
     (sin ky)
     (hypot (sin ky) (fma kx (* -0.16666666666666666 (* kx kx)) kx))))
   (*
    (sin th)
    (/
     (sin ky)
     (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-11) {
		tmp = sin(th) * (sin(ky) / hypot(sin(ky), fma(kx, (-0.16666666666666666 * (kx * kx)), kx)));
	} else {
		tmp = sin(th) * (sin(ky) / 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-11)
		tmp = Float64(sin(th) * Float64(sin(ky) / hypot(sin(ky), fma(kx, Float64(-0.16666666666666666 * Float64(kx * kx)), kx))));
	else
		tmp = Float64(sin(th) * Float64(sin(ky) / 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-11], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[(kx * N[(-0.16666666666666666 * N[(kx * kx), $MachinePrecision]), $MachinePrecision] + kx), $MachinePrecision] ^ 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[(N[Cos[N[(ky + ky), $MachinePrecision]], $MachinePrecision] * -0.5 + 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;{\sin kx}^{2} \leq 5 \cdot 10^{-11}:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \mathsf{fma}\left(kx, -0.16666666666666666 \cdot \left(kx \cdot kx\right), kx\right)\right)}\\

\mathbf{else}:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\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)) < 5.00000000000000018e-11

    1. Initial program 87.9%

      \[\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.9

        \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
    4. Applied egg-rr99.9%

      \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
    5. Taylor expanded in kx around 0

      \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{kx \cdot \left(1 + \frac{-1}{6} \cdot {kx}^{2}\right)}\right)} \cdot \sin th \]
    6. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx \cdot \color{blue}{\left(\frac{-1}{6} \cdot {kx}^{2} + 1\right)}\right)} \cdot \sin th \]
      2. distribute-lft-inN/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{kx \cdot \left(\frac{-1}{6} \cdot {kx}^{2}\right) + kx \cdot 1}\right)} \cdot \sin th \]
      3. *-rgt-identityN/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx \cdot \left(\frac{-1}{6} \cdot {kx}^{2}\right) + \color{blue}{kx}\right)} \cdot \sin th \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{\mathsf{fma}\left(kx, \frac{-1}{6} \cdot {kx}^{2}, kx\right)}\right)} \cdot \sin th \]
      5. lower-*.f64N/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \mathsf{fma}\left(kx, \color{blue}{\frac{-1}{6} \cdot {kx}^{2}}, kx\right)\right)} \cdot \sin th \]
      6. unpow2N/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \mathsf{fma}\left(kx, \frac{-1}{6} \cdot \color{blue}{\left(kx \cdot kx\right)}, kx\right)\right)} \cdot \sin th \]
      7. lower-*.f6499.9

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \mathsf{fma}\left(kx, -0.16666666666666666 \cdot \color{blue}{\left(kx \cdot kx\right)}, kx\right)\right)} \cdot \sin th \]
    7. Simplified99.9%

      \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{\mathsf{fma}\left(kx, -0.16666666666666666 \cdot \left(kx \cdot kx\right), kx\right)}\right)} \cdot \sin th \]

    if 5.00000000000000018e-11 < (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 egg-rr99.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. Step-by-step derivation
      1. lift-+.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 \color{blue}{\left(ky + ky\right)}\right)}} \cdot \sin th \]
      2. lift-cos.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 \color{blue}{\cos \left(ky + ky\right)}\right)}} \cdot \sin th \]
      3. lift-*.f64N/A

        \[\leadsto \frac{\sin ky}{\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)}} \cdot \sin th \]
      4. +-commutativeN/A

        \[\leadsto \frac{\sin ky}{\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)}} \cdot \sin th \]
      5. lift-*.f64N/A

        \[\leadsto \frac{\sin ky}{\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)}} \cdot \sin th \]
      6. *-commutativeN/A

        \[\leadsto \frac{\sin ky}{\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)}} \cdot \sin th \]
      7. lift-+.f64N/A

        \[\leadsto \frac{\sin ky}{\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)}} \cdot \sin th \]
      8. flip-+N/A

        \[\leadsto \frac{\sin ky}{\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)}} \cdot \sin th \]
      9. +-inversesN/A

        \[\leadsto \frac{\sin ky}{\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)}} \cdot \sin th \]
      10. +-inversesN/A

        \[\leadsto \frac{\sin ky}{\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)}} \cdot \sin th \]
      11. +-inversesN/A

        \[\leadsto \frac{\sin ky}{\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)}} \cdot \sin th \]
      12. +-inversesN/A

        \[\leadsto \frac{\sin ky}{\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)}} \cdot \sin th \]
      13. flip-+N/A

        \[\leadsto \frac{\sin ky}{\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)}} \cdot \sin th \]
      14. lift-+.f64N/A

        \[\leadsto \frac{\sin ky}{\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)}} \cdot \sin th \]
      15. lower-fma.f6429.0

        \[\leadsto \frac{\sin ky}{\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)}} \cdot \sin th \]
      16. lift-+.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, \mathsf{fma}\left(\cos \color{blue}{\left(kx + kx\right)}, \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
      17. flip-+N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, \mathsf{fma}\left(\cos \color{blue}{\left(\frac{kx \cdot kx - kx \cdot kx}{kx - kx}\right)}, \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
      18. +-inversesN/A

        \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, \mathsf{fma}\left(\cos \left(\frac{\color{blue}{0}}{kx - kx}\right), \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
      19. +-inversesN/A

        \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, \mathsf{fma}\left(\cos \left(\frac{0}{\color{blue}{0}}\right), \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
      20. +-inversesN/A

        \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, \mathsf{fma}\left(\cos \left(\frac{\color{blue}{ky \cdot ky - ky \cdot ky}}{0}\right), \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
      21. +-inversesN/A

        \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, \mathsf{fma}\left(\cos \left(\frac{ky \cdot ky - ky \cdot ky}{\color{blue}{ky - ky}}\right), \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
      22. flip-+N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, \mathsf{fma}\left(\cos \color{blue}{\left(ky + ky\right)}, \frac{-1}{2}, \frac{1}{2}\right)\right)}} \cdot \sin th \]
      23. lift-+.f6499.2

        \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, \mathsf{fma}\left(\cos \color{blue}{\left(ky + ky\right)}, -0.5, 0.5\right)\right)}} \cdot \sin th \]
    6. Applied egg-rr99.2%

      \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, \color{blue}{\mathsf{fma}\left(\cos \left(ky + ky\right), -0.5, 0.5\right)}\right)}} \cdot \sin th \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;{\sin kx}^{2} \leq 5 \cdot 10^{-11}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \mathsf{fma}\left(kx, -0.16666666666666666 \cdot \left(kx \cdot kx\right), kx\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\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 20: 49.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.072:\\ \;\;\;\;ky \cdot \left(\sin th \cdot \sqrt{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}\right)\\ \mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-165}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;\sin kx \leq 4 \cdot 10^{-75}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sqrt{kx \cdot kx + ky \cdot ky}}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin kx) -0.072)
   (* ky (* (sin th) (sqrt (/ 2.0 (- 1.0 (cos (* kx -2.0)))))))
   (if (<= (sin kx) 5e-165)
     (sin th)
     (if (<= (sin kx) 4e-75)
       (* (sin th) (/ (sin ky) (sqrt (+ (* kx kx) (* ky ky)))))
       (* (sin th) (/ (sin ky) (sin kx)))))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(kx) <= -0.072) {
		tmp = ky * (sin(th) * sqrt((2.0 / (1.0 - cos((kx * -2.0))))));
	} else if (sin(kx) <= 5e-165) {
		tmp = sin(th);
	} else if (sin(kx) <= 4e-75) {
		tmp = sin(th) * (sin(ky) / sqrt(((kx * kx) + (ky * ky))));
	} else {
		tmp = sin(th) * (sin(ky) / sin(kx));
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (sin(kx) <= (-0.072d0)) then
        tmp = ky * (sin(th) * sqrt((2.0d0 / (1.0d0 - cos((kx * (-2.0d0)))))))
    else if (sin(kx) <= 5d-165) then
        tmp = sin(th)
    else if (sin(kx) <= 4d-75) then
        tmp = sin(th) * (sin(ky) / sqrt(((kx * kx) + (ky * ky))))
    else
        tmp = sin(th) * (sin(ky) / sin(kx))
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (Math.sin(kx) <= -0.072) {
		tmp = ky * (Math.sin(th) * Math.sqrt((2.0 / (1.0 - Math.cos((kx * -2.0))))));
	} else if (Math.sin(kx) <= 5e-165) {
		tmp = Math.sin(th);
	} else if (Math.sin(kx) <= 4e-75) {
		tmp = Math.sin(th) * (Math.sin(ky) / Math.sqrt(((kx * kx) + (ky * ky))));
	} else {
		tmp = Math.sin(th) * (Math.sin(ky) / Math.sin(kx));
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if math.sin(kx) <= -0.072:
		tmp = ky * (math.sin(th) * math.sqrt((2.0 / (1.0 - math.cos((kx * -2.0))))))
	elif math.sin(kx) <= 5e-165:
		tmp = math.sin(th)
	elif math.sin(kx) <= 4e-75:
		tmp = math.sin(th) * (math.sin(ky) / math.sqrt(((kx * kx) + (ky * ky))))
	else:
		tmp = math.sin(th) * (math.sin(ky) / math.sin(kx))
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (sin(kx) <= -0.072)
		tmp = Float64(ky * Float64(sin(th) * sqrt(Float64(2.0 / Float64(1.0 - cos(Float64(kx * -2.0)))))));
	elseif (sin(kx) <= 5e-165)
		tmp = sin(th);
	elseif (sin(kx) <= 4e-75)
		tmp = Float64(sin(th) * Float64(sin(ky) / sqrt(Float64(Float64(kx * kx) + Float64(ky * ky)))));
	else
		tmp = Float64(sin(th) * Float64(sin(ky) / sin(kx)));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (sin(kx) <= -0.072)
		tmp = ky * (sin(th) * sqrt((2.0 / (1.0 - cos((kx * -2.0))))));
	elseif (sin(kx) <= 5e-165)
		tmp = sin(th);
	elseif (sin(kx) <= 4e-75)
		tmp = sin(th) * (sin(ky) / sqrt(((kx * kx) + (ky * ky))));
	else
		tmp = sin(th) * (sin(ky) / sin(kx));
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[N[Sin[kx], $MachinePrecision], -0.072], N[(ky * N[(N[Sin[th], $MachinePrecision] * N[Sqrt[N[(2.0 / N[(1.0 - N[Cos[N[(kx * -2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[kx], $MachinePrecision], 5e-165], N[Sin[th], $MachinePrecision], If[LessEqual[N[Sin[kx], $MachinePrecision], 4e-75], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(kx * kx), $MachinePrecision] + N[(ky * ky), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\sin kx \leq -0.072:\\
\;\;\;\;ky \cdot \left(\sin th \cdot \sqrt{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}\right)\\

\mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-165}:\\
\;\;\;\;\sin th\\

\mathbf{elif}\;\sin kx \leq 4 \cdot 10^{-75}:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\sqrt{kx \cdot kx + ky \cdot ky}}\\

\mathbf{else}:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (sin.f64 kx) < -0.0719999999999999946

    1. Initial program 99.3%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Applied egg-rr99.2%

      \[\leadsto \color{blue}{\left(\sin ky \cdot \sin th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, 0.5 + -0.5 \cdot \cos \left(ky + ky\right)\right)}}} \]
    4. Taylor expanded in ky around 0

      \[\leadsto \color{blue}{\left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \cdot \sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}}} \]
    5. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}} \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right)} \]
      2. lower-*.f64N/A

        \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}} \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right)} \]
      3. lower-sqrt.f64N/A

        \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}}} \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
      4. lower-/.f64N/A

        \[\leadsto \sqrt{\color{blue}{\frac{1}{1 - \cos \left(2 \cdot kx\right)}}} \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
      5. metadata-evalN/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(\color{blue}{\left(\mathsf{neg}\left(-2\right)\right)} \cdot kx\right)}} \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
      6. distribute-lft-neg-inN/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \color{blue}{\left(\mathsf{neg}\left(-2 \cdot kx\right)\right)}}} \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
      7. lower--.f64N/A

        \[\leadsto \sqrt{\frac{1}{\color{blue}{1 - \cos \left(\mathsf{neg}\left(-2 \cdot kx\right)\right)}}} \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
      8. cos-negN/A

        \[\leadsto \sqrt{\frac{1}{1 - \color{blue}{\cos \left(-2 \cdot kx\right)}}} \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
      9. lower-cos.f64N/A

        \[\leadsto \sqrt{\frac{1}{1 - \color{blue}{\cos \left(-2 \cdot kx\right)}}} \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
      10. *-commutativeN/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \color{blue}{\left(kx \cdot -2\right)}}} \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
      11. lower-*.f64N/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \color{blue}{\left(kx \cdot -2\right)}}} \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
      12. associate-*r*N/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \cdot \color{blue}{\left(\left(ky \cdot \sin th\right) \cdot \sqrt{2}\right)} \]
      13. lower-*.f64N/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \cdot \color{blue}{\left(\left(ky \cdot \sin th\right) \cdot \sqrt{2}\right)} \]
      14. lower-*.f64N/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \cdot \left(\color{blue}{\left(ky \cdot \sin th\right)} \cdot \sqrt{2}\right) \]
      15. lower-sin.f64N/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \cdot \left(\left(ky \cdot \color{blue}{\sin th}\right) \cdot \sqrt{2}\right) \]
      16. lower-sqrt.f6435.1

        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \cdot \left(\left(ky \cdot \sin th\right) \cdot \color{blue}{\sqrt{2}}\right) \]
    6. Simplified35.1%

      \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \cdot \left(\left(ky \cdot \sin th\right) \cdot \sqrt{2}\right)} \]
    7. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \color{blue}{\left(kx \cdot -2\right)}}} \cdot \left(\left(ky \cdot \sin th\right) \cdot \sqrt{2}\right) \]
      2. lift-cos.f64N/A

        \[\leadsto \sqrt{\frac{1}{1 - \color{blue}{\cos \left(kx \cdot -2\right)}}} \cdot \left(\left(ky \cdot \sin th\right) \cdot \sqrt{2}\right) \]
      3. lift--.f64N/A

        \[\leadsto \sqrt{\frac{1}{\color{blue}{1 - \cos \left(kx \cdot -2\right)}}} \cdot \left(\left(ky \cdot \sin th\right) \cdot \sqrt{2}\right) \]
      4. lift-/.f64N/A

        \[\leadsto \sqrt{\color{blue}{\frac{1}{1 - \cos \left(kx \cdot -2\right)}}} \cdot \left(\left(ky \cdot \sin th\right) \cdot \sqrt{2}\right) \]
      5. lift-sqrt.f64N/A

        \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}}} \cdot \left(\left(ky \cdot \sin th\right) \cdot \sqrt{2}\right) \]
      6. lift-sin.f64N/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \cdot \left(\left(ky \cdot \color{blue}{\sin th}\right) \cdot \sqrt{2}\right) \]
      7. lift-*.f64N/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \cdot \left(\color{blue}{\left(ky \cdot \sin th\right)} \cdot \sqrt{2}\right) \]
      8. lift-sqrt.f64N/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \cdot \left(\left(ky \cdot \sin th\right) \cdot \color{blue}{\sqrt{2}}\right) \]
      9. lift-*.f64N/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \cdot \color{blue}{\left(\left(ky \cdot \sin th\right) \cdot \sqrt{2}\right)} \]
      10. *-commutativeN/A

        \[\leadsto \color{blue}{\left(\left(ky \cdot \sin th\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}}} \]
      11. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(\left(ky \cdot \sin th\right) \cdot \sqrt{2}\right)} \cdot \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \]
      12. lift-*.f64N/A

        \[\leadsto \left(\color{blue}{\left(ky \cdot \sin th\right)} \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \]
      13. associate-*l*N/A

        \[\leadsto \color{blue}{\left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right)} \cdot \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \]
      14. associate-*l*N/A

        \[\leadsto \color{blue}{ky \cdot \left(\left(\sin th \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}}\right)} \]
      15. associate-*r*N/A

        \[\leadsto ky \cdot \color{blue}{\left(\sin th \cdot \left(\sqrt{2} \cdot \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}}\right)\right)} \]
    8. Applied egg-rr35.2%

      \[\leadsto \color{blue}{ky \cdot \left(\sin th \cdot \sqrt{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}\right)} \]

    if -0.0719999999999999946 < (sin.f64 kx) < 4.99999999999999981e-165

    1. Initial program 83.3%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Taylor expanded in kx around 0

      \[\leadsto \color{blue}{\sin th} \]
    4. Step-by-step derivation
      1. lower-sin.f6441.7

        \[\leadsto \color{blue}{\sin th} \]
    5. Simplified41.7%

      \[\leadsto \color{blue}{\sin th} \]

    if 4.99999999999999981e-165 < (sin.f64 kx) < 3.9999999999999998e-75

    1. Initial program 99.3%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Taylor expanded in ky around 0

      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{ky}^{2}}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot ky}}} \cdot \sin th \]
      2. lower-*.f6459.2

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot ky}}} \cdot \sin th \]
    5. Simplified59.2%

      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot ky}}} \cdot \sin th \]
    6. Taylor expanded in kx around 0

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + ky \cdot ky}} \cdot \sin th \]
    7. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + ky \cdot ky}} \cdot \sin th \]
      2. lower-*.f6459.2

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + ky \cdot ky}} \cdot \sin th \]
    8. Simplified59.2%

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + ky \cdot ky}} \cdot \sin th \]

    if 3.9999999999999998e-75 < (sin.f64 kx)

    1. Initial program 99.4%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Taylor expanded in ky around 0

      \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
    4. Step-by-step derivation
      1. lower-sin.f6465.5

        \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
    5. Simplified65.5%

      \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
  3. Recombined 4 regimes into one program.
  4. Final simplification49.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.072:\\ \;\;\;\;ky \cdot \left(\sin th \cdot \sqrt{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}\right)\\ \mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-165}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;\sin kx \leq 4 \cdot 10^{-75}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sqrt{kx \cdot kx + ky \cdot ky}}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\ \end{array} \]
  5. Add Preprocessing

Alternative 21: 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^{-52}:\\ \;\;\;\;-0.16666666666666666 \cdot \left(th \cdot \left(th \cdot th\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) 2e-52)
   (* -0.16666666666666666 (* th (* th th)))
   (sin th)))
double code(double kx, double ky, double th) {
	double tmp;
	if ((sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) <= 2e-52) {
		tmp = -0.16666666666666666 * (th * (th * th));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if ((sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) <= 2d-52) then
        tmp = (-0.16666666666666666d0) * (th * (th * th))
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if ((Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) <= 2e-52) {
		tmp = -0.16666666666666666 * (th * (th * th));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if (math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))) <= 2e-52:
		tmp = -0.16666666666666666 * (th * (th * th))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 2e-52)
		tmp = Float64(-0.16666666666666666 * Float64(th * Float64(th * th)));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if ((sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 2e-52)
		tmp = -0.16666666666666666 * (th * (th * th));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2e-52], N[(-0.16666666666666666 * N[(th * N[(th * th), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 2 \cdot 10^{-52}:\\
\;\;\;\;-0.16666666666666666 \cdot \left(th \cdot \left(th \cdot th\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\sin th\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 2e-52

    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.f643.6

        \[\leadsto \color{blue}{\sin th} \]
    5. Simplified3.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. +-commutativeN/A

        \[\leadsto th \cdot \color{blue}{\left(\frac{-1}{6} \cdot {th}^{2} + 1\right)} \]
      2. distribute-lft-inN/A

        \[\leadsto \color{blue}{th \cdot \left(\frac{-1}{6} \cdot {th}^{2}\right) + th \cdot 1} \]
      3. *-rgt-identityN/A

        \[\leadsto th \cdot \left(\frac{-1}{6} \cdot {th}^{2}\right) + \color{blue}{th} \]
      4. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(th, \frac{-1}{6} \cdot {th}^{2}, th\right)} \]
      5. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(th, \color{blue}{\frac{-1}{6} \cdot {th}^{2}}, th\right) \]
      6. unpow2N/A

        \[\leadsto \mathsf{fma}\left(th, \frac{-1}{6} \cdot \color{blue}{\left(th \cdot th\right)}, th\right) \]
      7. lower-*.f643.4

        \[\leadsto \mathsf{fma}\left(th, -0.16666666666666666 \cdot \color{blue}{\left(th \cdot th\right)}, th\right) \]
    8. Simplified3.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\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-*.f6414.7

        \[\leadsto -0.16666666666666666 \cdot \left(th \cdot \color{blue}{\left(th \cdot th\right)}\right) \]
    11. Simplified14.7%

      \[\leadsto \color{blue}{-0.16666666666666666 \cdot \left(th \cdot \left(th \cdot th\right)\right)} \]

    if 2e-52 < (/.f64 (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.f6458.6

        \[\leadsto \color{blue}{\sin th} \]
    5. Simplified58.6%

      \[\leadsto \color{blue}{\sin th} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 22: 46.6% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 2.1 \cdot 10^{-174}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{elif}\;ky \leq 0.0012:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, ky \cdot ky\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
 (if (<= ky 2.1e-174)
   (* (sin th) (/ ky (sin kx)))
   (if (<= ky 0.0012)
     (*
      (sin th)
      (/ (sin ky) (sqrt (fma (- 1.0 (cos (+ kx kx))) 0.5 (* ky ky)))))
     (* (sin th) (/ (sin ky) (sqrt (fma -0.5 (cos (* ky -2.0)) 0.5)))))))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 2.1e-174) {
		tmp = sin(th) * (ky / sin(kx));
	} else if (ky <= 0.0012) {
		tmp = sin(th) * (sin(ky) / sqrt(fma((1.0 - cos((kx + kx))), 0.5, (ky * ky))));
	} else {
		tmp = sin(th) * (sin(ky) / sqrt(fma(-0.5, cos((ky * -2.0)), 0.5)));
	}
	return tmp;
}
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= 2.1e-174)
		tmp = Float64(sin(th) * Float64(ky / sin(kx)));
	elseif (ky <= 0.0012)
		tmp = Float64(sin(th) * Float64(sin(ky) / sqrt(fma(Float64(1.0 - cos(Float64(kx + kx))), 0.5, Float64(ky * ky)))));
	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_] := If[LessEqual[ky, 2.1e-174], N[(N[Sin[th], $MachinePrecision] * N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[ky, 0.0012], 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[(ky * ky), $MachinePrecision]), $MachinePrecision]], $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}
\mathbf{if}\;ky \leq 2.1 \cdot 10^{-174}:\\
\;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\

\mathbf{elif}\;ky \leq 0.0012:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, ky \cdot ky\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 3 regimes
  2. if ky < 2.1000000000000001e-174

    1. Initial program 90.9%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-sin.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{{\color{blue}{\sin kx}}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      2. lift-pow.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
      3. lift-sin.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\color{blue}{\sin ky}}^{2}}} \cdot \sin th \]
      4. lift-pow.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{\sin ky}^{2}}}} \cdot \sin th \]
      5. +-commutativeN/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
      6. lift-pow.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2}} + {\sin kx}^{2}}} \cdot \sin th \]
      7. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
      8. lift-pow.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
      9. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
      10. lower-hypot.f6499.6

        \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
    4. Applied egg-rr99.6%

      \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
    5. Taylor expanded in ky around 0

      \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]
    6. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]
      2. lower-sin.f6435.8

        \[\leadsto \frac{ky}{\color{blue}{\sin kx}} \cdot \sin th \]
    7. Simplified35.8%

      \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]

    if 2.1000000000000001e-174 < ky < 0.00119999999999999989

    1. Initial program 97.9%

      \[\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.f6497.9

        \[\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 egg-rr51.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{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, \color{blue}{{ky}^{2}}\right)}} \cdot \sin th \]
    6. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), \frac{1}{2}, \color{blue}{ky \cdot ky}\right)}} \cdot \sin th \]
      2. lower-*.f6483.1

        \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, \color{blue}{ky \cdot ky}\right)}} \cdot \sin th \]
    7. Simplified83.1%

      \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, \color{blue}{ky \cdot ky}\right)}} \cdot \sin th \]

    if 0.00119999999999999989 < ky

    1. Initial program 99.6%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-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 egg-rr99.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 kx around 0

      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)}}} \cdot \sin th \]
    6. Step-by-step derivation
      1. lower-sqrt.f64N/A

        \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)}}} \cdot \sin th \]
      2. +-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 \]
      3. 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 \]
      4. 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 \]
      5. 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 \]
      6. 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 \]
      7. 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 \]
      8. *-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 \]
      9. lower-*.f6449.8

        \[\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. Simplified49.8%

      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\mathsf{fma}\left(-0.5, \cos \left(ky \cdot -2\right), 0.5\right)}}} \cdot \sin th \]
  3. Recombined 3 regimes into one program.
  4. Final simplification45.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq 2.1 \cdot 10^{-174}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{elif}\;ky \leq 0.0012:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sqrt{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, ky \cdot ky\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: 36.9% accurate, 2.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;kx \leq 1.1 \cdot 10^{-161}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;kx \leq 2000000000:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sqrt{kx \cdot kx + ky \cdot ky}}\\ \mathbf{else}:\\ \;\;\;\;ky \cdot \left(\sin th \cdot \sqrt{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}\right)\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= kx 1.1e-161)
   (sin th)
   (if (<= kx 2000000000.0)
     (* (sin th) (/ (sin ky) (sqrt (+ (* kx kx) (* ky ky)))))
     (* ky (* (sin th) (sqrt (/ 2.0 (- 1.0 (cos (* kx -2.0))))))))))
double code(double kx, double ky, double th) {
	double tmp;
	if (kx <= 1.1e-161) {
		tmp = sin(th);
	} else if (kx <= 2000000000.0) {
		tmp = sin(th) * (sin(ky) / sqrt(((kx * kx) + (ky * ky))));
	} else {
		tmp = ky * (sin(th) * sqrt((2.0 / (1.0 - cos((kx * -2.0))))));
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (kx <= 1.1d-161) then
        tmp = sin(th)
    else if (kx <= 2000000000.0d0) then
        tmp = sin(th) * (sin(ky) / sqrt(((kx * kx) + (ky * ky))))
    else
        tmp = ky * (sin(th) * sqrt((2.0d0 / (1.0d0 - cos((kx * (-2.0d0)))))))
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (kx <= 1.1e-161) {
		tmp = Math.sin(th);
	} else if (kx <= 2000000000.0) {
		tmp = Math.sin(th) * (Math.sin(ky) / Math.sqrt(((kx * kx) + (ky * ky))));
	} else {
		tmp = ky * (Math.sin(th) * Math.sqrt((2.0 / (1.0 - Math.cos((kx * -2.0))))));
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if kx <= 1.1e-161:
		tmp = math.sin(th)
	elif kx <= 2000000000.0:
		tmp = math.sin(th) * (math.sin(ky) / math.sqrt(((kx * kx) + (ky * ky))))
	else:
		tmp = ky * (math.sin(th) * math.sqrt((2.0 / (1.0 - math.cos((kx * -2.0))))))
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (kx <= 1.1e-161)
		tmp = sin(th);
	elseif (kx <= 2000000000.0)
		tmp = Float64(sin(th) * Float64(sin(ky) / sqrt(Float64(Float64(kx * kx) + Float64(ky * ky)))));
	else
		tmp = Float64(ky * Float64(sin(th) * sqrt(Float64(2.0 / Float64(1.0 - cos(Float64(kx * -2.0)))))));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (kx <= 1.1e-161)
		tmp = sin(th);
	elseif (kx <= 2000000000.0)
		tmp = sin(th) * (sin(ky) / sqrt(((kx * kx) + (ky * ky))));
	else
		tmp = ky * (sin(th) * sqrt((2.0 / (1.0 - cos((kx * -2.0))))));
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[kx, 1.1e-161], N[Sin[th], $MachinePrecision], If[LessEqual[kx, 2000000000.0], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(kx * kx), $MachinePrecision] + N[(ky * ky), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(ky * N[(N[Sin[th], $MachinePrecision] * N[Sqrt[N[(2.0 / N[(1.0 - N[Cos[N[(kx * -2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;kx \leq 1.1 \cdot 10^{-161}:\\
\;\;\;\;\sin th\\

\mathbf{elif}\;kx \leq 2000000000:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\sqrt{kx \cdot kx + ky \cdot ky}}\\

\mathbf{else}:\\
\;\;\;\;ky \cdot \left(\sin th \cdot \sqrt{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if kx < 1.10000000000000001e-161

    1. Initial program 90.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.f6427.0

        \[\leadsto \color{blue}{\sin th} \]
    5. Simplified27.0%

      \[\leadsto \color{blue}{\sin th} \]

    if 1.10000000000000001e-161 < kx < 2e9

    1. Initial program 99.5%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Taylor expanded in ky around 0

      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{ky}^{2}}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot ky}}} \cdot \sin th \]
      2. lower-*.f6461.0

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot ky}}} \cdot \sin th \]
    5. Simplified61.0%

      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot ky}}} \cdot \sin th \]
    6. Taylor expanded in kx around 0

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + ky \cdot ky}} \cdot \sin th \]
    7. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + ky \cdot ky}} \cdot \sin th \]
      2. lower-*.f6460.2

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + ky \cdot ky}} \cdot \sin th \]
    8. Simplified60.2%

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + ky \cdot ky}} \cdot \sin th \]

    if 2e9 < kx

    1. Initial program 99.3%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Applied egg-rr99.3%

      \[\leadsto \color{blue}{\left(\sin ky \cdot \sin th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, 0.5 + -0.5 \cdot \cos \left(ky + ky\right)\right)}}} \]
    4. Taylor expanded in ky around 0

      \[\leadsto \color{blue}{\left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \cdot \sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}}} \]
    5. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}} \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right)} \]
      2. lower-*.f64N/A

        \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}} \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right)} \]
      3. lower-sqrt.f64N/A

        \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}}} \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
      4. lower-/.f64N/A

        \[\leadsto \sqrt{\color{blue}{\frac{1}{1 - \cos \left(2 \cdot kx\right)}}} \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
      5. metadata-evalN/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(\color{blue}{\left(\mathsf{neg}\left(-2\right)\right)} \cdot kx\right)}} \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
      6. distribute-lft-neg-inN/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \color{blue}{\left(\mathsf{neg}\left(-2 \cdot kx\right)\right)}}} \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
      7. lower--.f64N/A

        \[\leadsto \sqrt{\frac{1}{\color{blue}{1 - \cos \left(\mathsf{neg}\left(-2 \cdot kx\right)\right)}}} \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
      8. cos-negN/A

        \[\leadsto \sqrt{\frac{1}{1 - \color{blue}{\cos \left(-2 \cdot kx\right)}}} \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
      9. lower-cos.f64N/A

        \[\leadsto \sqrt{\frac{1}{1 - \color{blue}{\cos \left(-2 \cdot kx\right)}}} \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
      10. *-commutativeN/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \color{blue}{\left(kx \cdot -2\right)}}} \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
      11. lower-*.f64N/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \color{blue}{\left(kx \cdot -2\right)}}} \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
      12. associate-*r*N/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \cdot \color{blue}{\left(\left(ky \cdot \sin th\right) \cdot \sqrt{2}\right)} \]
      13. lower-*.f64N/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \cdot \color{blue}{\left(\left(ky \cdot \sin th\right) \cdot \sqrt{2}\right)} \]
      14. lower-*.f64N/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \cdot \left(\color{blue}{\left(ky \cdot \sin th\right)} \cdot \sqrt{2}\right) \]
      15. lower-sin.f64N/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \cdot \left(\left(ky \cdot \color{blue}{\sin th}\right) \cdot \sqrt{2}\right) \]
      16. lower-sqrt.f6446.5

        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \cdot \left(\left(ky \cdot \sin th\right) \cdot \color{blue}{\sqrt{2}}\right) \]
    6. Simplified46.5%

      \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \cdot \left(\left(ky \cdot \sin th\right) \cdot \sqrt{2}\right)} \]
    7. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \color{blue}{\left(kx \cdot -2\right)}}} \cdot \left(\left(ky \cdot \sin th\right) \cdot \sqrt{2}\right) \]
      2. lift-cos.f64N/A

        \[\leadsto \sqrt{\frac{1}{1 - \color{blue}{\cos \left(kx \cdot -2\right)}}} \cdot \left(\left(ky \cdot \sin th\right) \cdot \sqrt{2}\right) \]
      3. lift--.f64N/A

        \[\leadsto \sqrt{\frac{1}{\color{blue}{1 - \cos \left(kx \cdot -2\right)}}} \cdot \left(\left(ky \cdot \sin th\right) \cdot \sqrt{2}\right) \]
      4. lift-/.f64N/A

        \[\leadsto \sqrt{\color{blue}{\frac{1}{1 - \cos \left(kx \cdot -2\right)}}} \cdot \left(\left(ky \cdot \sin th\right) \cdot \sqrt{2}\right) \]
      5. lift-sqrt.f64N/A

        \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}}} \cdot \left(\left(ky \cdot \sin th\right) \cdot \sqrt{2}\right) \]
      6. lift-sin.f64N/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \cdot \left(\left(ky \cdot \color{blue}{\sin th}\right) \cdot \sqrt{2}\right) \]
      7. lift-*.f64N/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \cdot \left(\color{blue}{\left(ky \cdot \sin th\right)} \cdot \sqrt{2}\right) \]
      8. lift-sqrt.f64N/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \cdot \left(\left(ky \cdot \sin th\right) \cdot \color{blue}{\sqrt{2}}\right) \]
      9. lift-*.f64N/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \cdot \color{blue}{\left(\left(ky \cdot \sin th\right) \cdot \sqrt{2}\right)} \]
      10. *-commutativeN/A

        \[\leadsto \color{blue}{\left(\left(ky \cdot \sin th\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}}} \]
      11. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(\left(ky \cdot \sin th\right) \cdot \sqrt{2}\right)} \cdot \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \]
      12. lift-*.f64N/A

        \[\leadsto \left(\color{blue}{\left(ky \cdot \sin th\right)} \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \]
      13. associate-*l*N/A

        \[\leadsto \color{blue}{\left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right)} \cdot \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \]
      14. associate-*l*N/A

        \[\leadsto \color{blue}{ky \cdot \left(\left(\sin th \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}}\right)} \]
      15. associate-*r*N/A

        \[\leadsto ky \cdot \color{blue}{\left(\sin th \cdot \left(\sqrt{2} \cdot \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}}\right)\right)} \]
    8. Applied egg-rr46.5%

      \[\leadsto \color{blue}{ky \cdot \left(\sin th \cdot \sqrt{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification36.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;kx \leq 1.1 \cdot 10^{-161}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;kx \leq 2000000000:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sqrt{kx \cdot kx + ky \cdot ky}}\\ \mathbf{else}:\\ \;\;\;\;ky \cdot \left(\sin th \cdot \sqrt{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 24: 35.4% accurate, 2.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;kx \leq 1.1 \cdot 10^{-161}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;kx \leq 2000000000:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{kx}\\ \mathbf{else}:\\ \;\;\;\;ky \cdot \left(\sin th \cdot \sqrt{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}\right)\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= kx 1.1e-161)
   (sin th)
   (if (<= kx 2000000000.0)
     (* (sin th) (/ (sin ky) kx))
     (* ky (* (sin th) (sqrt (/ 2.0 (- 1.0 (cos (* kx -2.0))))))))))
double code(double kx, double ky, double th) {
	double tmp;
	if (kx <= 1.1e-161) {
		tmp = sin(th);
	} else if (kx <= 2000000000.0) {
		tmp = sin(th) * (sin(ky) / kx);
	} else {
		tmp = ky * (sin(th) * sqrt((2.0 / (1.0 - cos((kx * -2.0))))));
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (kx <= 1.1d-161) then
        tmp = sin(th)
    else if (kx <= 2000000000.0d0) then
        tmp = sin(th) * (sin(ky) / kx)
    else
        tmp = ky * (sin(th) * sqrt((2.0d0 / (1.0d0 - cos((kx * (-2.0d0)))))))
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (kx <= 1.1e-161) {
		tmp = Math.sin(th);
	} else if (kx <= 2000000000.0) {
		tmp = Math.sin(th) * (Math.sin(ky) / kx);
	} else {
		tmp = ky * (Math.sin(th) * Math.sqrt((2.0 / (1.0 - Math.cos((kx * -2.0))))));
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if kx <= 1.1e-161:
		tmp = math.sin(th)
	elif kx <= 2000000000.0:
		tmp = math.sin(th) * (math.sin(ky) / kx)
	else:
		tmp = ky * (math.sin(th) * math.sqrt((2.0 / (1.0 - math.cos((kx * -2.0))))))
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (kx <= 1.1e-161)
		tmp = sin(th);
	elseif (kx <= 2000000000.0)
		tmp = Float64(sin(th) * Float64(sin(ky) / kx));
	else
		tmp = Float64(ky * Float64(sin(th) * sqrt(Float64(2.0 / Float64(1.0 - cos(Float64(kx * -2.0)))))));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (kx <= 1.1e-161)
		tmp = sin(th);
	elseif (kx <= 2000000000.0)
		tmp = sin(th) * (sin(ky) / kx);
	else
		tmp = ky * (sin(th) * sqrt((2.0 / (1.0 - cos((kx * -2.0))))));
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[kx, 1.1e-161], N[Sin[th], $MachinePrecision], If[LessEqual[kx, 2000000000.0], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / kx), $MachinePrecision]), $MachinePrecision], N[(ky * N[(N[Sin[th], $MachinePrecision] * N[Sqrt[N[(2.0 / N[(1.0 - N[Cos[N[(kx * -2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;kx \leq 1.1 \cdot 10^{-161}:\\
\;\;\;\;\sin th\\

\mathbf{elif}\;kx \leq 2000000000:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{kx}\\

\mathbf{else}:\\
\;\;\;\;ky \cdot \left(\sin th \cdot \sqrt{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if kx < 1.10000000000000001e-161

    1. Initial program 90.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.f6427.0

        \[\leadsto \color{blue}{\sin th} \]
    5. Simplified27.0%

      \[\leadsto \color{blue}{\sin th} \]

    if 1.10000000000000001e-161 < kx < 2e9

    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 egg-rr46.3%

      \[\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}{\color{blue}{\sqrt{\frac{1}{2}} \cdot \sqrt{1 - \cos \left(2 \cdot kx\right)}}} \cdot \sin th \]
    6. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\frac{1}{2}} \cdot \sqrt{1 - \cos \left(2 \cdot kx\right)}}} \cdot \sin th \]
      2. lower-sqrt.f64N/A

        \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\frac{1}{2}}} \cdot \sqrt{1 - \cos \left(2 \cdot kx\right)}} \cdot \sin th \]
      3. lower-sqrt.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2}} \cdot \color{blue}{\sqrt{1 - \cos \left(2 \cdot kx\right)}}} \cdot \sin th \]
      4. metadata-evalN/A

        \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2}} \cdot \sqrt{1 - \cos \left(\color{blue}{\left(\mathsf{neg}\left(-2\right)\right)} \cdot kx\right)}} \cdot \sin th \]
      5. distribute-lft-neg-inN/A

        \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2}} \cdot \sqrt{1 - \cos \color{blue}{\left(\mathsf{neg}\left(-2 \cdot kx\right)\right)}}} \cdot \sin th \]
      6. lower--.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2}} \cdot \sqrt{\color{blue}{1 - \cos \left(\mathsf{neg}\left(-2 \cdot kx\right)\right)}}} \cdot \sin th \]
      7. cos-negN/A

        \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2}} \cdot \sqrt{1 - \color{blue}{\cos \left(-2 \cdot kx\right)}}} \cdot \sin th \]
      8. lower-cos.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2}} \cdot \sqrt{1 - \color{blue}{\cos \left(-2 \cdot kx\right)}}} \cdot \sin th \]
      9. *-commutativeN/A

        \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2}} \cdot \sqrt{1 - \cos \color{blue}{\left(kx \cdot -2\right)}}} \cdot \sin th \]
      10. lower-*.f647.3

        \[\leadsto \frac{\sin ky}{\sqrt{0.5} \cdot \sqrt{1 - \cos \color{blue}{\left(kx \cdot -2\right)}}} \cdot \sin th \]
    7. Simplified7.3%

      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{0.5} \cdot \sqrt{1 - \cos \left(kx \cdot -2\right)}}} \cdot \sin th \]
    8. Taylor expanded in kx around 0

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{kx}} \]
    9. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \frac{\color{blue}{\sin th \cdot \sin ky}}{kx} \]
      2. associate-/l*N/A

        \[\leadsto \color{blue}{\sin th \cdot \frac{\sin ky}{kx}} \]
      3. lower-*.f64N/A

        \[\leadsto \color{blue}{\sin th \cdot \frac{\sin ky}{kx}} \]
      4. lower-sin.f64N/A

        \[\leadsto \color{blue}{\sin th} \cdot \frac{\sin ky}{kx} \]
      5. lower-/.f64N/A

        \[\leadsto \sin th \cdot \color{blue}{\frac{\sin ky}{kx}} \]
      6. lower-sin.f6452.7

        \[\leadsto \sin th \cdot \frac{\color{blue}{\sin ky}}{kx} \]
    10. Simplified52.7%

      \[\leadsto \color{blue}{\sin th \cdot \frac{\sin ky}{kx}} \]

    if 2e9 < kx

    1. Initial program 99.3%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Applied egg-rr99.3%

      \[\leadsto \color{blue}{\left(\sin ky \cdot \sin th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(1 - \cos \left(kx + kx\right), 0.5, 0.5 + -0.5 \cdot \cos \left(ky + ky\right)\right)}}} \]
    4. Taylor expanded in ky around 0

      \[\leadsto \color{blue}{\left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \cdot \sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}}} \]
    5. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}} \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right)} \]
      2. lower-*.f64N/A

        \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}} \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right)} \]
      3. lower-sqrt.f64N/A

        \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(2 \cdot kx\right)}}} \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
      4. lower-/.f64N/A

        \[\leadsto \sqrt{\color{blue}{\frac{1}{1 - \cos \left(2 \cdot kx\right)}}} \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
      5. metadata-evalN/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(\color{blue}{\left(\mathsf{neg}\left(-2\right)\right)} \cdot kx\right)}} \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
      6. distribute-lft-neg-inN/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \color{blue}{\left(\mathsf{neg}\left(-2 \cdot kx\right)\right)}}} \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
      7. lower--.f64N/A

        \[\leadsto \sqrt{\frac{1}{\color{blue}{1 - \cos \left(\mathsf{neg}\left(-2 \cdot kx\right)\right)}}} \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
      8. cos-negN/A

        \[\leadsto \sqrt{\frac{1}{1 - \color{blue}{\cos \left(-2 \cdot kx\right)}}} \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
      9. lower-cos.f64N/A

        \[\leadsto \sqrt{\frac{1}{1 - \color{blue}{\cos \left(-2 \cdot kx\right)}}} \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
      10. *-commutativeN/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \color{blue}{\left(kx \cdot -2\right)}}} \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
      11. lower-*.f64N/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \color{blue}{\left(kx \cdot -2\right)}}} \cdot \left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
      12. associate-*r*N/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \cdot \color{blue}{\left(\left(ky \cdot \sin th\right) \cdot \sqrt{2}\right)} \]
      13. lower-*.f64N/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \cdot \color{blue}{\left(\left(ky \cdot \sin th\right) \cdot \sqrt{2}\right)} \]
      14. lower-*.f64N/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \cdot \left(\color{blue}{\left(ky \cdot \sin th\right)} \cdot \sqrt{2}\right) \]
      15. lower-sin.f64N/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \cdot \left(\left(ky \cdot \color{blue}{\sin th}\right) \cdot \sqrt{2}\right) \]
      16. lower-sqrt.f6446.5

        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \cdot \left(\left(ky \cdot \sin th\right) \cdot \color{blue}{\sqrt{2}}\right) \]
    6. Simplified46.5%

      \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \cdot \left(\left(ky \cdot \sin th\right) \cdot \sqrt{2}\right)} \]
    7. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \color{blue}{\left(kx \cdot -2\right)}}} \cdot \left(\left(ky \cdot \sin th\right) \cdot \sqrt{2}\right) \]
      2. lift-cos.f64N/A

        \[\leadsto \sqrt{\frac{1}{1 - \color{blue}{\cos \left(kx \cdot -2\right)}}} \cdot \left(\left(ky \cdot \sin th\right) \cdot \sqrt{2}\right) \]
      3. lift--.f64N/A

        \[\leadsto \sqrt{\frac{1}{\color{blue}{1 - \cos \left(kx \cdot -2\right)}}} \cdot \left(\left(ky \cdot \sin th\right) \cdot \sqrt{2}\right) \]
      4. lift-/.f64N/A

        \[\leadsto \sqrt{\color{blue}{\frac{1}{1 - \cos \left(kx \cdot -2\right)}}} \cdot \left(\left(ky \cdot \sin th\right) \cdot \sqrt{2}\right) \]
      5. lift-sqrt.f64N/A

        \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}}} \cdot \left(\left(ky \cdot \sin th\right) \cdot \sqrt{2}\right) \]
      6. lift-sin.f64N/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \cdot \left(\left(ky \cdot \color{blue}{\sin th}\right) \cdot \sqrt{2}\right) \]
      7. lift-*.f64N/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \cdot \left(\color{blue}{\left(ky \cdot \sin th\right)} \cdot \sqrt{2}\right) \]
      8. lift-sqrt.f64N/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \cdot \left(\left(ky \cdot \sin th\right) \cdot \color{blue}{\sqrt{2}}\right) \]
      9. lift-*.f64N/A

        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \cdot \color{blue}{\left(\left(ky \cdot \sin th\right) \cdot \sqrt{2}\right)} \]
      10. *-commutativeN/A

        \[\leadsto \color{blue}{\left(\left(ky \cdot \sin th\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}}} \]
      11. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(\left(ky \cdot \sin th\right) \cdot \sqrt{2}\right)} \cdot \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \]
      12. lift-*.f64N/A

        \[\leadsto \left(\color{blue}{\left(ky \cdot \sin th\right)} \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \]
      13. associate-*l*N/A

        \[\leadsto \color{blue}{\left(ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right)} \cdot \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}} \]
      14. associate-*l*N/A

        \[\leadsto \color{blue}{ky \cdot \left(\left(\sin th \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}}\right)} \]
      15. associate-*r*N/A

        \[\leadsto ky \cdot \color{blue}{\left(\sin th \cdot \left(\sqrt{2} \cdot \sqrt{\frac{1}{1 - \cos \left(kx \cdot -2\right)}}\right)\right)} \]
    8. Applied egg-rr46.5%

      \[\leadsto \color{blue}{ky \cdot \left(\sin th \cdot \sqrt{\frac{2}{1 - \cos \left(kx \cdot -2\right)}}\right)} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 25: 19.2% accurate, 5.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq 5.5 \cdot 10^{-165}:\\ \;\;\;\;-0.16666666666666666 \cdot \left(th \cdot \left(th \cdot th\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\right)\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin ky) 5.5e-165)
   (* -0.16666666666666666 (* th (* th th)))
   (fma th (* -0.16666666666666666 (* th th)) th)))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(ky) <= 5.5e-165) {
		tmp = -0.16666666666666666 * (th * (th * th));
	} else {
		tmp = fma(th, (-0.16666666666666666 * (th * th)), th);
	}
	return tmp;
}
function code(kx, ky, th)
	tmp = 0.0
	if (sin(ky) <= 5.5e-165)
		tmp = Float64(-0.16666666666666666 * Float64(th * Float64(th * th)));
	else
		tmp = fma(th, Float64(-0.16666666666666666 * Float64(th * th)), th);
	end
	return tmp
end
code[kx_, ky_, th_] := If[LessEqual[N[Sin[ky], $MachinePrecision], 5.5e-165], N[(-0.16666666666666666 * N[(th * N[(th * th), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(th * N[(-0.16666666666666666 * N[(th * th), $MachinePrecision]), $MachinePrecision] + th), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq 5.5 \cdot 10^{-165}:\\
\;\;\;\;-0.16666666666666666 \cdot \left(th \cdot \left(th \cdot th\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (sin.f64 ky) < 5.49999999999999969e-165

    1. Initial program 91.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.f644.0

        \[\leadsto \color{blue}{\sin th} \]
    5. Simplified4.0%

      \[\leadsto \color{blue}{\sin th} \]
    6. Taylor expanded in th around 0

      \[\leadsto \color{blue}{th \cdot \left(1 + \frac{-1}{6} \cdot {th}^{2}\right)} \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto th \cdot \color{blue}{\left(\frac{-1}{6} \cdot {th}^{2} + 1\right)} \]
      2. distribute-lft-inN/A

        \[\leadsto \color{blue}{th \cdot \left(\frac{-1}{6} \cdot {th}^{2}\right) + th \cdot 1} \]
      3. *-rgt-identityN/A

        \[\leadsto th \cdot \left(\frac{-1}{6} \cdot {th}^{2}\right) + \color{blue}{th} \]
      4. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(th, \frac{-1}{6} \cdot {th}^{2}, th\right)} \]
      5. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(th, \color{blue}{\frac{-1}{6} \cdot {th}^{2}}, th\right) \]
      6. unpow2N/A

        \[\leadsto \mathsf{fma}\left(th, \frac{-1}{6} \cdot \color{blue}{\left(th \cdot th\right)}, th\right) \]
      7. lower-*.f643.3

        \[\leadsto \mathsf{fma}\left(th, -0.16666666666666666 \cdot \color{blue}{\left(th \cdot th\right)}, th\right) \]
    8. Simplified3.3%

      \[\leadsto \color{blue}{\mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\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-*.f6413.7

        \[\leadsto -0.16666666666666666 \cdot \left(th \cdot \color{blue}{\left(th \cdot th\right)}\right) \]
    11. Simplified13.7%

      \[\leadsto \color{blue}{-0.16666666666666666 \cdot \left(th \cdot \left(th \cdot th\right)\right)} \]

    if 5.49999999999999969e-165 < (sin.f64 ky)

    1. Initial program 99.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.f6449.8

        \[\leadsto \color{blue}{\sin th} \]
    5. Simplified49.8%

      \[\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. +-commutativeN/A

        \[\leadsto th \cdot \color{blue}{\left(\frac{-1}{6} \cdot {th}^{2} + 1\right)} \]
      2. distribute-lft-inN/A

        \[\leadsto \color{blue}{th \cdot \left(\frac{-1}{6} \cdot {th}^{2}\right) + th \cdot 1} \]
      3. *-rgt-identityN/A

        \[\leadsto th \cdot \left(\frac{-1}{6} \cdot {th}^{2}\right) + \color{blue}{th} \]
      4. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(th, \frac{-1}{6} \cdot {th}^{2}, th\right)} \]
      5. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(th, \color{blue}{\frac{-1}{6} \cdot {th}^{2}}, th\right) \]
      6. unpow2N/A

        \[\leadsto \mathsf{fma}\left(th, \frac{-1}{6} \cdot \color{blue}{\left(th \cdot th\right)}, th\right) \]
      7. lower-*.f6423.3

        \[\leadsto \mathsf{fma}\left(th, -0.16666666666666666 \cdot \color{blue}{\left(th \cdot th\right)}, th\right) \]
    8. Simplified23.3%

      \[\leadsto \color{blue}{\mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 26: 11.0% accurate, 39.5× speedup?

\[\begin{array}{l} \\ -0.16666666666666666 \cdot \left(th \cdot \left(th \cdot th\right)\right) \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (* -0.16666666666666666 (* th (* th th))))
double code(double kx, double ky, double th) {
	return -0.16666666666666666 * (th * (th * th));
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    code = (-0.16666666666666666d0) * (th * (th * th))
end function
public static double code(double kx, double ky, double th) {
	return -0.16666666666666666 * (th * (th * th));
}
def code(kx, ky, th):
	return -0.16666666666666666 * (th * (th * th))
function code(kx, ky, th)
	return Float64(-0.16666666666666666 * Float64(th * Float64(th * th)))
end
function tmp = code(kx, ky, th)
	tmp = -0.16666666666666666 * (th * (th * th));
end
code[kx_, ky_, th_] := N[(-0.16666666666666666 * N[(th * N[(th * th), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
-0.16666666666666666 \cdot \left(th \cdot \left(th \cdot th\right)\right)
\end{array}
Derivation
  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.f6419.9

      \[\leadsto \color{blue}{\sin th} \]
  5. Simplified19.9%

    \[\leadsto \color{blue}{\sin th} \]
  6. Taylor expanded in th around 0

    \[\leadsto \color{blue}{th \cdot \left(1 + \frac{-1}{6} \cdot {th}^{2}\right)} \]
  7. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto th \cdot \color{blue}{\left(\frac{-1}{6} \cdot {th}^{2} + 1\right)} \]
    2. distribute-lft-inN/A

      \[\leadsto \color{blue}{th \cdot \left(\frac{-1}{6} \cdot {th}^{2}\right) + th \cdot 1} \]
    3. *-rgt-identityN/A

      \[\leadsto th \cdot \left(\frac{-1}{6} \cdot {th}^{2}\right) + \color{blue}{th} \]
    4. lower-fma.f64N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(th, \frac{-1}{6} \cdot {th}^{2}, th\right)} \]
    5. lower-*.f64N/A

      \[\leadsto \mathsf{fma}\left(th, \color{blue}{\frac{-1}{6} \cdot {th}^{2}}, th\right) \]
    6. unpow2N/A

      \[\leadsto \mathsf{fma}\left(th, \frac{-1}{6} \cdot \color{blue}{\left(th \cdot th\right)}, th\right) \]
    7. lower-*.f6410.2

      \[\leadsto \mathsf{fma}\left(th, -0.16666666666666666 \cdot \color{blue}{\left(th \cdot th\right)}, th\right) \]
  8. Simplified10.2%

    \[\leadsto \color{blue}{\mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\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-*.f6411.3

      \[\leadsto -0.16666666666666666 \cdot \left(th \cdot \color{blue}{\left(th \cdot th\right)}\right) \]
  11. Simplified11.3%

    \[\leadsto \color{blue}{-0.16666666666666666 \cdot \left(th \cdot \left(th \cdot th\right)\right)} \]
  12. Add Preprocessing

Reproduce

?
herbie shell --seed 2024219 
(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)))