Toniolo and Linder, Equation (3a)

Percentage Accurate: 98.1% → 99.6%
Time: 14.9s
Alternatives: 9
Speedup: 2.0×

Specification

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

\\
\sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}}\right)}
\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 9 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: 98.1% accurate, 1.0× speedup?

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

\\
\sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}}\right)}
\end{array}

Alternative 1: 99.6% accurate, 2.0× speedup?

\[\begin{array}{l} kx_m = \left|kx\right| \\ ky_m = \left|ky\right| \\ [l, Om, kx_m, ky_m] = \mathsf{sort}([l, Om, kx_m, ky_m])\\ \\ \begin{array}{l} t_0 := \frac{Om}{\sin ky\_m}\\ \sqrt{\mathsf{fma}\left(0.5, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\ell \cdot 4}{t\_0}, \frac{\ell}{t\_0}, 1\right)}}, 0.5\right)} \end{array} \end{array} \]
kx_m = (fabs.f64 kx)
ky_m = (fabs.f64 ky)
NOTE: l, Om, kx_m, and ky_m should be sorted in increasing order before calling this function.
(FPCore (l Om kx_m ky_m)
 :precision binary64
 (let* ((t_0 (/ Om (sin ky_m))))
   (sqrt (fma 0.5 (sqrt (/ 1.0 (fma (/ (* l 4.0) t_0) (/ l t_0) 1.0))) 0.5))))
kx_m = fabs(kx);
ky_m = fabs(ky);
assert(l < Om && Om < kx_m && kx_m < ky_m);
double code(double l, double Om, double kx_m, double ky_m) {
	double t_0 = Om / sin(ky_m);
	return sqrt(fma(0.5, sqrt((1.0 / fma(((l * 4.0) / t_0), (l / t_0), 1.0))), 0.5));
}
kx_m = abs(kx)
ky_m = abs(ky)
l, Om, kx_m, ky_m = sort([l, Om, kx_m, ky_m])
function code(l, Om, kx_m, ky_m)
	t_0 = Float64(Om / sin(ky_m))
	return sqrt(fma(0.5, sqrt(Float64(1.0 / fma(Float64(Float64(l * 4.0) / t_0), Float64(l / t_0), 1.0))), 0.5))
end
kx_m = N[Abs[kx], $MachinePrecision]
ky_m = N[Abs[ky], $MachinePrecision]
NOTE: l, Om, kx_m, and ky_m should be sorted in increasing order before calling this function.
code[l_, Om_, kx$95$m_, ky$95$m_] := Block[{t$95$0 = N[(Om / N[Sin[ky$95$m], $MachinePrecision]), $MachinePrecision]}, N[Sqrt[N[(0.5 * N[Sqrt[N[(1.0 / N[(N[(N[(l * 4.0), $MachinePrecision] / t$95$0), $MachinePrecision] * N[(l / t$95$0), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + 0.5), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
kx_m = \left|kx\right|
\\
ky_m = \left|ky\right|
\\
[l, Om, kx_m, ky_m] = \mathsf{sort}([l, Om, kx_m, ky_m])\\
\\
\begin{array}{l}
t_0 := \frac{Om}{\sin ky\_m}\\
\sqrt{\mathsf{fma}\left(0.5, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\ell \cdot 4}{t\_0}, \frac{\ell}{t\_0}, 1\right)}}, 0.5\right)}
\end{array}
\end{array}
Derivation
  1. Initial program 96.9%

    \[\sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}}\right)} \]
  2. Add Preprocessing
  3. Taylor expanded in kx around 0

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

      \[\leadsto \sqrt{\frac{1}{2} \cdot \color{blue}{\left(\sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot {\sin ky}^{2}}{{Om}^{2}}}} + 1\right)}} \]
    2. distribute-lft-inN/A

      \[\leadsto \sqrt{\color{blue}{\frac{1}{2} \cdot \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot {\sin ky}^{2}}{{Om}^{2}}}} + \frac{1}{2} \cdot 1}} \]
    3. metadata-evalN/A

      \[\leadsto \sqrt{\frac{1}{2} \cdot \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot {\sin ky}^{2}}{{Om}^{2}}}} + \color{blue}{\frac{1}{2}}} \]
    4. accelerator-lowering-fma.f64N/A

      \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot {\sin ky}^{2}}{{Om}^{2}}}}, \frac{1}{2}\right)}} \]
  5. Simplified80.4%

    \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(0.5, \sqrt{\frac{1}{\mathsf{fma}\left(4 \cdot \left(\ell \cdot \ell\right), \frac{{\sin ky}^{2}}{Om \cdot Om}, 1\right)}}, 0.5\right)}} \]
  6. Step-by-step derivation
    1. pow2N/A

      \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\left(4 \cdot \left(\ell \cdot \ell\right)\right) \cdot \frac{\color{blue}{\sin ky \cdot \sin ky}}{Om \cdot Om} + 1}}, \frac{1}{2}\right)} \]
    2. clear-numN/A

      \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\left(4 \cdot \left(\ell \cdot \ell\right)\right) \cdot \color{blue}{\frac{1}{\frac{Om \cdot Om}{\sin ky \cdot \sin ky}}} + 1}}, \frac{1}{2}\right)} \]
    3. un-div-invN/A

      \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\color{blue}{\frac{4 \cdot \left(\ell \cdot \ell\right)}{\frac{Om \cdot Om}{\sin ky \cdot \sin ky}}} + 1}}, \frac{1}{2}\right)} \]
    4. associate-*r*N/A

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

      \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\frac{\color{blue}{\left(\ell \cdot 4\right)} \cdot \ell}{\frac{Om \cdot Om}{\sin ky \cdot \sin ky}} + 1}}, \frac{1}{2}\right)} \]
    6. times-fracN/A

      \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\frac{\left(\ell \cdot 4\right) \cdot \ell}{\color{blue}{\frac{Om}{\sin ky} \cdot \frac{Om}{\sin ky}}} + 1}}, \frac{1}{2}\right)} \]
    7. times-fracN/A

      \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\color{blue}{\frac{\ell \cdot 4}{\frac{Om}{\sin ky}} \cdot \frac{\ell}{\frac{Om}{\sin ky}}} + 1}}, \frac{1}{2}\right)} \]
    8. accelerator-lowering-fma.f64N/A

      \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\color{blue}{\mathsf{fma}\left(\frac{\ell \cdot 4}{\frac{Om}{\sin ky}}, \frac{\ell}{\frac{Om}{\sin ky}}, 1\right)}}}, \frac{1}{2}\right)} \]
    9. /-lowering-/.f64N/A

      \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\mathsf{fma}\left(\color{blue}{\frac{\ell \cdot 4}{\frac{Om}{\sin ky}}}, \frac{\ell}{\frac{Om}{\sin ky}}, 1\right)}}, \frac{1}{2}\right)} \]
    10. *-lowering-*.f64N/A

      \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\color{blue}{\ell \cdot 4}}{\frac{Om}{\sin ky}}, \frac{\ell}{\frac{Om}{\sin ky}}, 1\right)}}, \frac{1}{2}\right)} \]
    11. /-lowering-/.f64N/A

      \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\ell \cdot 4}{\color{blue}{\frac{Om}{\sin ky}}}, \frac{\ell}{\frac{Om}{\sin ky}}, 1\right)}}, \frac{1}{2}\right)} \]
    12. sin-lowering-sin.f64N/A

      \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\ell \cdot 4}{\frac{Om}{\color{blue}{\sin ky}}}, \frac{\ell}{\frac{Om}{\sin ky}}, 1\right)}}, \frac{1}{2}\right)} \]
    13. /-lowering-/.f64N/A

      \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\ell \cdot 4}{\frac{Om}{\sin ky}}, \color{blue}{\frac{\ell}{\frac{Om}{\sin ky}}}, 1\right)}}, \frac{1}{2}\right)} \]
    14. /-lowering-/.f64N/A

      \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\ell \cdot 4}{\frac{Om}{\sin ky}}, \frac{\ell}{\color{blue}{\frac{Om}{\sin ky}}}, 1\right)}}, \frac{1}{2}\right)} \]
    15. sin-lowering-sin.f6496.2

      \[\leadsto \sqrt{\mathsf{fma}\left(0.5, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\ell \cdot 4}{\frac{Om}{\sin ky}}, \frac{\ell}{\frac{Om}{\color{blue}{\sin ky}}}, 1\right)}}, 0.5\right)} \]
  7. Applied egg-rr96.2%

    \[\leadsto \sqrt{\mathsf{fma}\left(0.5, \sqrt{\frac{1}{\color{blue}{\mathsf{fma}\left(\frac{\ell \cdot 4}{\frac{Om}{\sin ky}}, \frac{\ell}{\frac{Om}{\sin ky}}, 1\right)}}}, 0.5\right)} \]
  8. Add Preprocessing

Alternative 2: 98.9% accurate, 1.5× speedup?

\[\begin{array}{l} kx_m = \left|kx\right| \\ ky_m = \left|ky\right| \\ [l, Om, kx_m, ky_m] = \mathsf{sort}([l, Om, kx_m, ky_m])\\ \\ \begin{array}{l} \mathbf{if}\;{\sin ky\_m}^{2} \leq 2 \cdot 10^{-34}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(0.5, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\ell \cdot 4}{\frac{Om}{\sin ky\_m}}, \frac{\ell \cdot ky\_m}{Om}, 1\right)}}, 0.5\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(1 + \frac{1}{\sqrt{\mathsf{fma}\left(4 \cdot \frac{\ell}{Om}, \frac{\ell \cdot \mathsf{fma}\left(-0.5, \cos \left(ky\_m \cdot -2\right), 0.5\right)}{Om}, 1\right)}}\right)}\\ \end{array} \end{array} \]
kx_m = (fabs.f64 kx)
ky_m = (fabs.f64 ky)
NOTE: l, Om, kx_m, and ky_m should be sorted in increasing order before calling this function.
(FPCore (l Om kx_m ky_m)
 :precision binary64
 (if (<= (pow (sin ky_m) 2.0) 2e-34)
   (sqrt
    (fma
     0.5
     (sqrt (/ 1.0 (fma (/ (* l 4.0) (/ Om (sin ky_m))) (/ (* l ky_m) Om) 1.0)))
     0.5))
   (sqrt
    (*
     0.5
     (+
      1.0
      (/
       1.0
       (sqrt
        (fma
         (* 4.0 (/ l Om))
         (/ (* l (fma -0.5 (cos (* ky_m -2.0)) 0.5)) Om)
         1.0))))))))
kx_m = fabs(kx);
ky_m = fabs(ky);
assert(l < Om && Om < kx_m && kx_m < ky_m);
double code(double l, double Om, double kx_m, double ky_m) {
	double tmp;
	if (pow(sin(ky_m), 2.0) <= 2e-34) {
		tmp = sqrt(fma(0.5, sqrt((1.0 / fma(((l * 4.0) / (Om / sin(ky_m))), ((l * ky_m) / Om), 1.0))), 0.5));
	} else {
		tmp = sqrt((0.5 * (1.0 + (1.0 / sqrt(fma((4.0 * (l / Om)), ((l * fma(-0.5, cos((ky_m * -2.0)), 0.5)) / Om), 1.0))))));
	}
	return tmp;
}
kx_m = abs(kx)
ky_m = abs(ky)
l, Om, kx_m, ky_m = sort([l, Om, kx_m, ky_m])
function code(l, Om, kx_m, ky_m)
	tmp = 0.0
	if ((sin(ky_m) ^ 2.0) <= 2e-34)
		tmp = sqrt(fma(0.5, sqrt(Float64(1.0 / fma(Float64(Float64(l * 4.0) / Float64(Om / sin(ky_m))), Float64(Float64(l * ky_m) / Om), 1.0))), 0.5));
	else
		tmp = sqrt(Float64(0.5 * Float64(1.0 + Float64(1.0 / sqrt(fma(Float64(4.0 * Float64(l / Om)), Float64(Float64(l * fma(-0.5, cos(Float64(ky_m * -2.0)), 0.5)) / Om), 1.0))))));
	end
	return tmp
end
kx_m = N[Abs[kx], $MachinePrecision]
ky_m = N[Abs[ky], $MachinePrecision]
NOTE: l, Om, kx_m, and ky_m should be sorted in increasing order before calling this function.
code[l_, Om_, kx$95$m_, ky$95$m_] := If[LessEqual[N[Power[N[Sin[ky$95$m], $MachinePrecision], 2.0], $MachinePrecision], 2e-34], N[Sqrt[N[(0.5 * N[Sqrt[N[(1.0 / N[(N[(N[(l * 4.0), $MachinePrecision] / N[(Om / N[Sin[ky$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(l * ky$95$m), $MachinePrecision] / Om), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + 0.5), $MachinePrecision]], $MachinePrecision], N[Sqrt[N[(0.5 * N[(1.0 + N[(1.0 / N[Sqrt[N[(N[(4.0 * N[(l / Om), $MachinePrecision]), $MachinePrecision] * N[(N[(l * N[(-0.5 * N[Cos[N[(ky$95$m * -2.0), $MachinePrecision]], $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision] / Om), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
kx_m = \left|kx\right|
\\
ky_m = \left|ky\right|
\\
[l, Om, kx_m, ky_m] = \mathsf{sort}([l, Om, kx_m, ky_m])\\
\\
\begin{array}{l}
\mathbf{if}\;{\sin ky\_m}^{2} \leq 2 \cdot 10^{-34}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(0.5, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\ell \cdot 4}{\frac{Om}{\sin ky\_m}}, \frac{\ell \cdot ky\_m}{Om}, 1\right)}}, 0.5\right)}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(1 + \frac{1}{\sqrt{\mathsf{fma}\left(4 \cdot \frac{\ell}{Om}, \frac{\ell \cdot \mathsf{fma}\left(-0.5, \cos \left(ky\_m \cdot -2\right), 0.5\right)}{Om}, 1\right)}}\right)}\\


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

    1. Initial program 93.3%

      \[\sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in kx around 0

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

        \[\leadsto \sqrt{\frac{1}{2} \cdot \color{blue}{\left(\sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot {\sin ky}^{2}}{{Om}^{2}}}} + 1\right)}} \]
      2. distribute-lft-inN/A

        \[\leadsto \sqrt{\color{blue}{\frac{1}{2} \cdot \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot {\sin ky}^{2}}{{Om}^{2}}}} + \frac{1}{2} \cdot 1}} \]
      3. metadata-evalN/A

        \[\leadsto \sqrt{\frac{1}{2} \cdot \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot {\sin ky}^{2}}{{Om}^{2}}}} + \color{blue}{\frac{1}{2}}} \]
      4. accelerator-lowering-fma.f64N/A

        \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot {\sin ky}^{2}}{{Om}^{2}}}}, \frac{1}{2}\right)}} \]
    5. Simplified67.9%

      \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(0.5, \sqrt{\frac{1}{\mathsf{fma}\left(4 \cdot \left(\ell \cdot \ell\right), \frac{{\sin ky}^{2}}{Om \cdot Om}, 1\right)}}, 0.5\right)}} \]
    6. Step-by-step derivation
      1. pow2N/A

        \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\left(4 \cdot \left(\ell \cdot \ell\right)\right) \cdot \frac{\color{blue}{\sin ky \cdot \sin ky}}{Om \cdot Om} + 1}}, \frac{1}{2}\right)} \]
      2. clear-numN/A

        \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\left(4 \cdot \left(\ell \cdot \ell\right)\right) \cdot \color{blue}{\frac{1}{\frac{Om \cdot Om}{\sin ky \cdot \sin ky}}} + 1}}, \frac{1}{2}\right)} \]
      3. un-div-invN/A

        \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\color{blue}{\frac{4 \cdot \left(\ell \cdot \ell\right)}{\frac{Om \cdot Om}{\sin ky \cdot \sin ky}}} + 1}}, \frac{1}{2}\right)} \]
      4. associate-*r*N/A

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

        \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\frac{\color{blue}{\left(\ell \cdot 4\right)} \cdot \ell}{\frac{Om \cdot Om}{\sin ky \cdot \sin ky}} + 1}}, \frac{1}{2}\right)} \]
      6. times-fracN/A

        \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\frac{\left(\ell \cdot 4\right) \cdot \ell}{\color{blue}{\frac{Om}{\sin ky} \cdot \frac{Om}{\sin ky}}} + 1}}, \frac{1}{2}\right)} \]
      7. times-fracN/A

        \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\color{blue}{\frac{\ell \cdot 4}{\frac{Om}{\sin ky}} \cdot \frac{\ell}{\frac{Om}{\sin ky}}} + 1}}, \frac{1}{2}\right)} \]
      8. accelerator-lowering-fma.f64N/A

        \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\color{blue}{\mathsf{fma}\left(\frac{\ell \cdot 4}{\frac{Om}{\sin ky}}, \frac{\ell}{\frac{Om}{\sin ky}}, 1\right)}}}, \frac{1}{2}\right)} \]
      9. /-lowering-/.f64N/A

        \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\mathsf{fma}\left(\color{blue}{\frac{\ell \cdot 4}{\frac{Om}{\sin ky}}}, \frac{\ell}{\frac{Om}{\sin ky}}, 1\right)}}, \frac{1}{2}\right)} \]
      10. *-lowering-*.f64N/A

        \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\color{blue}{\ell \cdot 4}}{\frac{Om}{\sin ky}}, \frac{\ell}{\frac{Om}{\sin ky}}, 1\right)}}, \frac{1}{2}\right)} \]
      11. /-lowering-/.f64N/A

        \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\ell \cdot 4}{\color{blue}{\frac{Om}{\sin ky}}}, \frac{\ell}{\frac{Om}{\sin ky}}, 1\right)}}, \frac{1}{2}\right)} \]
      12. sin-lowering-sin.f64N/A

        \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\ell \cdot 4}{\frac{Om}{\color{blue}{\sin ky}}}, \frac{\ell}{\frac{Om}{\sin ky}}, 1\right)}}, \frac{1}{2}\right)} \]
      13. /-lowering-/.f64N/A

        \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\ell \cdot 4}{\frac{Om}{\sin ky}}, \color{blue}{\frac{\ell}{\frac{Om}{\sin ky}}}, 1\right)}}, \frac{1}{2}\right)} \]
      14. /-lowering-/.f64N/A

        \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\ell \cdot 4}{\frac{Om}{\sin ky}}, \frac{\ell}{\color{blue}{\frac{Om}{\sin ky}}}, 1\right)}}, \frac{1}{2}\right)} \]
      15. sin-lowering-sin.f6491.9

        \[\leadsto \sqrt{\mathsf{fma}\left(0.5, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\ell \cdot 4}{\frac{Om}{\sin ky}}, \frac{\ell}{\frac{Om}{\color{blue}{\sin ky}}}, 1\right)}}, 0.5\right)} \]
    7. Applied egg-rr91.9%

      \[\leadsto \sqrt{\mathsf{fma}\left(0.5, \sqrt{\frac{1}{\color{blue}{\mathsf{fma}\left(\frac{\ell \cdot 4}{\frac{Om}{\sin ky}}, \frac{\ell}{\frac{Om}{\sin ky}}, 1\right)}}}, 0.5\right)} \]
    8. Taylor expanded in ky around 0

      \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\ell \cdot 4}{\frac{Om}{\sin ky}}, \color{blue}{\frac{ky \cdot \ell}{Om}}, 1\right)}}, \frac{1}{2}\right)} \]
    9. Step-by-step derivation
      1. /-lowering-/.f64N/A

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

        \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\ell \cdot 4}{\frac{Om}{\sin ky}}, \frac{\color{blue}{\ell \cdot ky}}{Om}, 1\right)}}, \frac{1}{2}\right)} \]
      3. *-lowering-*.f6491.9

        \[\leadsto \sqrt{\mathsf{fma}\left(0.5, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\ell \cdot 4}{\frac{Om}{\sin ky}}, \frac{\color{blue}{\ell \cdot ky}}{Om}, 1\right)}}, 0.5\right)} \]
    10. Simplified91.9%

      \[\leadsto \sqrt{\mathsf{fma}\left(0.5, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\ell \cdot 4}{\frac{Om}{\sin ky}}, \color{blue}{\frac{\ell \cdot ky}{Om}}, 1\right)}}, 0.5\right)} \]

    if 1.99999999999999986e-34 < (pow.f64 (sin.f64 ky) #s(literal 2 binary64))

    1. Initial program 100.0%

      \[\sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}}\right)} \]
    2. Add Preprocessing
    3. Applied egg-rr100.0%

      \[\leadsto \sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{\color{blue}{\mathsf{fma}\left(\frac{\ell}{Om} \cdot 4, \frac{\ell}{Om} \cdot \left(\left(0.5 + -0.5 \cdot \cos \left(kx + kx\right)\right) + \left(0.5 + -0.5 \cdot \cos \left(ky + ky\right)\right)\right), 1\right)}}}\right)} \]
    4. Step-by-step derivation
      1. metadata-eval100.0

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

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

      \[\leadsto \sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{\mathsf{fma}\left(\frac{\ell}{Om} \cdot 4, \color{blue}{\frac{\ell \cdot \left(\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}{Om}}, 1\right)}}\right)} \]
    7. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{\mathsf{fma}\left(\frac{\ell}{Om} \cdot 4, \color{blue}{\frac{\ell \cdot \left(\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}{Om}}, 1\right)}}\right)} \]
      2. *-lowering-*.f64N/A

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

        \[\leadsto \sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{\mathsf{fma}\left(\frac{\ell}{Om} \cdot 4, \frac{\ell \cdot \color{blue}{\left(\frac{-1}{2} \cdot \cos \left(2 \cdot ky\right) + \frac{1}{2}\right)}}{Om}, 1\right)}}\right)} \]
      4. accelerator-lowering-fma.f64N/A

        \[\leadsto \sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{\mathsf{fma}\left(\frac{\ell}{Om} \cdot 4, \frac{\ell \cdot \color{blue}{\mathsf{fma}\left(\frac{-1}{2}, \cos \left(2 \cdot ky\right), \frac{1}{2}\right)}}{Om}, 1\right)}}\right)} \]
      5. metadata-evalN/A

        \[\leadsto \sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{\mathsf{fma}\left(\frac{\ell}{Om} \cdot 4, \frac{\ell \cdot \mathsf{fma}\left(\frac{-1}{2}, \cos \left(\color{blue}{\left(\mathsf{neg}\left(-2\right)\right)} \cdot ky\right), \frac{1}{2}\right)}{Om}, 1\right)}}\right)} \]
      6. distribute-lft-neg-inN/A

        \[\leadsto \sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{\mathsf{fma}\left(\frac{\ell}{Om} \cdot 4, \frac{\ell \cdot \mathsf{fma}\left(\frac{-1}{2}, \cos \color{blue}{\left(\mathsf{neg}\left(-2 \cdot ky\right)\right)}, \frac{1}{2}\right)}{Om}, 1\right)}}\right)} \]
      7. cos-negN/A

        \[\leadsto \sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{\mathsf{fma}\left(\frac{\ell}{Om} \cdot 4, \frac{\ell \cdot \mathsf{fma}\left(\frac{-1}{2}, \color{blue}{\cos \left(-2 \cdot ky\right)}, \frac{1}{2}\right)}{Om}, 1\right)}}\right)} \]
      8. cos-lowering-cos.f64N/A

        \[\leadsto \sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{\mathsf{fma}\left(\frac{\ell}{Om} \cdot 4, \frac{\ell \cdot \mathsf{fma}\left(\frac{-1}{2}, \color{blue}{\cos \left(-2 \cdot ky\right)}, \frac{1}{2}\right)}{Om}, 1\right)}}\right)} \]
      9. *-lowering-*.f64100.0

        \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{1}{\sqrt{\mathsf{fma}\left(\frac{\ell}{Om} \cdot 4, \frac{\ell \cdot \mathsf{fma}\left(-0.5, \cos \color{blue}{\left(-2 \cdot ky\right)}, 0.5\right)}{Om}, 1\right)}}\right)} \]
    8. Simplified100.0%

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

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

Alternative 3: 81.2% accurate, 2.9× speedup?

\[\begin{array}{l} kx_m = \left|kx\right| \\ ky_m = \left|ky\right| \\ [l, Om, kx_m, ky_m] = \mathsf{sort}([l, Om, kx_m, ky_m])\\ \\ \begin{array}{l} \mathbf{if}\;\ell \leq 2 \cdot 10^{-177}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(0.5, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\ell \cdot 4}{Om}, \frac{\ell}{Om} \cdot \mathsf{fma}\left(-0.5, \cos \left(kx\_m + kx\_m\right), 0.5\right), 1\right)}}, 0.5\right)}\\ \mathbf{elif}\;\ell \leq 1.6 \cdot 10^{+128}:\\ \;\;\;\;\sqrt{0.5 + 0.5 \cdot \sqrt{\frac{1}{\mathsf{fma}\left(4, \frac{\mathsf{fma}\left(-0.5, \cos \left(ky\_m \cdot -2\right), 0.5\right) \cdot \left(\ell \cdot \ell\right)}{Om \cdot Om}, 1\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(0.5, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\ell \cdot 4}{\frac{Om}{\sin ky\_m}}, \frac{\ell \cdot ky\_m}{Om}, 1\right)}}, 0.5\right)}\\ \end{array} \end{array} \]
kx_m = (fabs.f64 kx)
ky_m = (fabs.f64 ky)
NOTE: l, Om, kx_m, and ky_m should be sorted in increasing order before calling this function.
(FPCore (l Om kx_m ky_m)
 :precision binary64
 (if (<= l 2e-177)
   (sqrt
    (fma
     0.5
     (sqrt
      (/
       1.0
       (fma
        (/ (* l 4.0) Om)
        (* (/ l Om) (fma -0.5 (cos (+ kx_m kx_m)) 0.5))
        1.0)))
     0.5))
   (if (<= l 1.6e+128)
     (sqrt
      (+
       0.5
       (*
        0.5
        (sqrt
         (/
          1.0
          (fma
           4.0
           (/ (* (fma -0.5 (cos (* ky_m -2.0)) 0.5) (* l l)) (* Om Om))
           1.0))))))
     (sqrt
      (fma
       0.5
       (sqrt
        (/ 1.0 (fma (/ (* l 4.0) (/ Om (sin ky_m))) (/ (* l ky_m) Om) 1.0)))
       0.5)))))
kx_m = fabs(kx);
ky_m = fabs(ky);
assert(l < Om && Om < kx_m && kx_m < ky_m);
double code(double l, double Om, double kx_m, double ky_m) {
	double tmp;
	if (l <= 2e-177) {
		tmp = sqrt(fma(0.5, sqrt((1.0 / fma(((l * 4.0) / Om), ((l / Om) * fma(-0.5, cos((kx_m + kx_m)), 0.5)), 1.0))), 0.5));
	} else if (l <= 1.6e+128) {
		tmp = sqrt((0.5 + (0.5 * sqrt((1.0 / fma(4.0, ((fma(-0.5, cos((ky_m * -2.0)), 0.5) * (l * l)) / (Om * Om)), 1.0))))));
	} else {
		tmp = sqrt(fma(0.5, sqrt((1.0 / fma(((l * 4.0) / (Om / sin(ky_m))), ((l * ky_m) / Om), 1.0))), 0.5));
	}
	return tmp;
}
kx_m = abs(kx)
ky_m = abs(ky)
l, Om, kx_m, ky_m = sort([l, Om, kx_m, ky_m])
function code(l, Om, kx_m, ky_m)
	tmp = 0.0
	if (l <= 2e-177)
		tmp = sqrt(fma(0.5, sqrt(Float64(1.0 / fma(Float64(Float64(l * 4.0) / Om), Float64(Float64(l / Om) * fma(-0.5, cos(Float64(kx_m + kx_m)), 0.5)), 1.0))), 0.5));
	elseif (l <= 1.6e+128)
		tmp = sqrt(Float64(0.5 + Float64(0.5 * sqrt(Float64(1.0 / fma(4.0, Float64(Float64(fma(-0.5, cos(Float64(ky_m * -2.0)), 0.5) * Float64(l * l)) / Float64(Om * Om)), 1.0))))));
	else
		tmp = sqrt(fma(0.5, sqrt(Float64(1.0 / fma(Float64(Float64(l * 4.0) / Float64(Om / sin(ky_m))), Float64(Float64(l * ky_m) / Om), 1.0))), 0.5));
	end
	return tmp
end
kx_m = N[Abs[kx], $MachinePrecision]
ky_m = N[Abs[ky], $MachinePrecision]
NOTE: l, Om, kx_m, and ky_m should be sorted in increasing order before calling this function.
code[l_, Om_, kx$95$m_, ky$95$m_] := If[LessEqual[l, 2e-177], N[Sqrt[N[(0.5 * N[Sqrt[N[(1.0 / N[(N[(N[(l * 4.0), $MachinePrecision] / Om), $MachinePrecision] * N[(N[(l / Om), $MachinePrecision] * N[(-0.5 * N[Cos[N[(kx$95$m + kx$95$m), $MachinePrecision]], $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + 0.5), $MachinePrecision]], $MachinePrecision], If[LessEqual[l, 1.6e+128], N[Sqrt[N[(0.5 + N[(0.5 * N[Sqrt[N[(1.0 / N[(4.0 * N[(N[(N[(-0.5 * N[Cos[N[(ky$95$m * -2.0), $MachinePrecision]], $MachinePrecision] + 0.5), $MachinePrecision] * N[(l * l), $MachinePrecision]), $MachinePrecision] / N[(Om * Om), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[N[(0.5 * N[Sqrt[N[(1.0 / N[(N[(N[(l * 4.0), $MachinePrecision] / N[(Om / N[Sin[ky$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(l * ky$95$m), $MachinePrecision] / Om), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + 0.5), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
kx_m = \left|kx\right|
\\
ky_m = \left|ky\right|
\\
[l, Om, kx_m, ky_m] = \mathsf{sort}([l, Om, kx_m, ky_m])\\
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 2 \cdot 10^{-177}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(0.5, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\ell \cdot 4}{Om}, \frac{\ell}{Om} \cdot \mathsf{fma}\left(-0.5, \cos \left(kx\_m + kx\_m\right), 0.5\right), 1\right)}}, 0.5\right)}\\

\mathbf{elif}\;\ell \leq 1.6 \cdot 10^{+128}:\\
\;\;\;\;\sqrt{0.5 + 0.5 \cdot \sqrt{\frac{1}{\mathsf{fma}\left(4, \frac{\mathsf{fma}\left(-0.5, \cos \left(ky\_m \cdot -2\right), 0.5\right) \cdot \left(\ell \cdot \ell\right)}{Om \cdot Om}, 1\right)}}}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(0.5, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\ell \cdot 4}{\frac{Om}{\sin ky\_m}}, \frac{\ell \cdot ky\_m}{Om}, 1\right)}}, 0.5\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < 1.9999999999999999e-177

    1. Initial program 98.1%

      \[\sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in kx around 0

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

        \[\leadsto \sqrt{\frac{1}{2} \cdot \color{blue}{\left(\sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot {\sin ky}^{2}}{{Om}^{2}}}} + 1\right)}} \]
      2. distribute-lft-inN/A

        \[\leadsto \sqrt{\color{blue}{\frac{1}{2} \cdot \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot {\sin ky}^{2}}{{Om}^{2}}}} + \frac{1}{2} \cdot 1}} \]
      3. metadata-evalN/A

        \[\leadsto \sqrt{\frac{1}{2} \cdot \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot {\sin ky}^{2}}{{Om}^{2}}}} + \color{blue}{\frac{1}{2}}} \]
      4. accelerator-lowering-fma.f64N/A

        \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot {\sin ky}^{2}}{{Om}^{2}}}}, \frac{1}{2}\right)}} \]
    5. Simplified79.9%

      \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(0.5, \sqrt{\frac{1}{\mathsf{fma}\left(4 \cdot \left(\ell \cdot \ell\right), \frac{{\sin ky}^{2}}{Om \cdot Om}, 1\right)}}, 0.5\right)}} \]
    6. Applied egg-rr83.6%

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

    if 1.9999999999999999e-177 < l < 1.59999999999999993e128

    1. Initial program 100.0%

      \[\sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}}\right)} \]
    2. Add Preprocessing
    3. Applied egg-rr96.0%

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

      \[\leadsto \sqrt{\color{blue}{\frac{1}{2} \cdot \left(1 + \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot \left(\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}{{Om}^{2}}}}\right)}} \]
    5. Step-by-step derivation
      1. distribute-lft-inN/A

        \[\leadsto \sqrt{\color{blue}{\frac{1}{2} \cdot 1 + \frac{1}{2} \cdot \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot \left(\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}{{Om}^{2}}}}}} \]
      2. metadata-evalN/A

        \[\leadsto \sqrt{\color{blue}{\frac{1}{2}} + \frac{1}{2} \cdot \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot \left(\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}{{Om}^{2}}}}} \]
      3. +-lowering-+.f64N/A

        \[\leadsto \sqrt{\color{blue}{\frac{1}{2} + \frac{1}{2} \cdot \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot \left(\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}{{Om}^{2}}}}}} \]
      4. *-lowering-*.f64N/A

        \[\leadsto \sqrt{\frac{1}{2} + \color{blue}{\frac{1}{2} \cdot \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot \left(\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}{{Om}^{2}}}}}} \]
      5. sqrt-lowering-sqrt.f64N/A

        \[\leadsto \sqrt{\frac{1}{2} + \frac{1}{2} \cdot \color{blue}{\sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot \left(\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}{{Om}^{2}}}}}} \]
      6. /-lowering-/.f64N/A

        \[\leadsto \sqrt{\frac{1}{2} + \frac{1}{2} \cdot \sqrt{\color{blue}{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot \left(\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}{{Om}^{2}}}}}} \]
      7. +-commutativeN/A

        \[\leadsto \sqrt{\frac{1}{2} + \frac{1}{2} \cdot \sqrt{\frac{1}{\color{blue}{4 \cdot \frac{{\ell}^{2} \cdot \left(\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}{{Om}^{2}} + 1}}}} \]
      8. accelerator-lowering-fma.f64N/A

        \[\leadsto \sqrt{\frac{1}{2} + \frac{1}{2} \cdot \sqrt{\frac{1}{\color{blue}{\mathsf{fma}\left(4, \frac{{\ell}^{2} \cdot \left(\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}{{Om}^{2}}, 1\right)}}}} \]
    6. Simplified89.2%

      \[\leadsto \sqrt{\color{blue}{0.5 + 0.5 \cdot \sqrt{\frac{1}{\mathsf{fma}\left(4, \frac{\left(\ell \cdot \ell\right) \cdot \mathsf{fma}\left(-0.5, \cos \left(ky \cdot -2\right), 0.5\right)}{Om \cdot Om}, 1\right)}}}} \]

    if 1.59999999999999993e128 < l

    1. Initial program 88.1%

      \[\sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in kx around 0

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

        \[\leadsto \sqrt{\frac{1}{2} \cdot \color{blue}{\left(\sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot {\sin ky}^{2}}{{Om}^{2}}}} + 1\right)}} \]
      2. distribute-lft-inN/A

        \[\leadsto \sqrt{\color{blue}{\frac{1}{2} \cdot \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot {\sin ky}^{2}}{{Om}^{2}}}} + \frac{1}{2} \cdot 1}} \]
      3. metadata-evalN/A

        \[\leadsto \sqrt{\frac{1}{2} \cdot \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot {\sin ky}^{2}}{{Om}^{2}}}} + \color{blue}{\frac{1}{2}}} \]
      4. accelerator-lowering-fma.f64N/A

        \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot {\sin ky}^{2}}{{Om}^{2}}}}, \frac{1}{2}\right)}} \]
    5. Simplified66.7%

      \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(0.5, \sqrt{\frac{1}{\mathsf{fma}\left(4 \cdot \left(\ell \cdot \ell\right), \frac{{\sin ky}^{2}}{Om \cdot Om}, 1\right)}}, 0.5\right)}} \]
    6. Step-by-step derivation
      1. pow2N/A

        \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\left(4 \cdot \left(\ell \cdot \ell\right)\right) \cdot \frac{\color{blue}{\sin ky \cdot \sin ky}}{Om \cdot Om} + 1}}, \frac{1}{2}\right)} \]
      2. clear-numN/A

        \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\left(4 \cdot \left(\ell \cdot \ell\right)\right) \cdot \color{blue}{\frac{1}{\frac{Om \cdot Om}{\sin ky \cdot \sin ky}}} + 1}}, \frac{1}{2}\right)} \]
      3. un-div-invN/A

        \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\color{blue}{\frac{4 \cdot \left(\ell \cdot \ell\right)}{\frac{Om \cdot Om}{\sin ky \cdot \sin ky}}} + 1}}, \frac{1}{2}\right)} \]
      4. associate-*r*N/A

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

        \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\frac{\color{blue}{\left(\ell \cdot 4\right)} \cdot \ell}{\frac{Om \cdot Om}{\sin ky \cdot \sin ky}} + 1}}, \frac{1}{2}\right)} \]
      6. times-fracN/A

        \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\frac{\left(\ell \cdot 4\right) \cdot \ell}{\color{blue}{\frac{Om}{\sin ky} \cdot \frac{Om}{\sin ky}}} + 1}}, \frac{1}{2}\right)} \]
      7. times-fracN/A

        \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\color{blue}{\frac{\ell \cdot 4}{\frac{Om}{\sin ky}} \cdot \frac{\ell}{\frac{Om}{\sin ky}}} + 1}}, \frac{1}{2}\right)} \]
      8. accelerator-lowering-fma.f64N/A

        \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\color{blue}{\mathsf{fma}\left(\frac{\ell \cdot 4}{\frac{Om}{\sin ky}}, \frac{\ell}{\frac{Om}{\sin ky}}, 1\right)}}}, \frac{1}{2}\right)} \]
      9. /-lowering-/.f64N/A

        \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\mathsf{fma}\left(\color{blue}{\frac{\ell \cdot 4}{\frac{Om}{\sin ky}}}, \frac{\ell}{\frac{Om}{\sin ky}}, 1\right)}}, \frac{1}{2}\right)} \]
      10. *-lowering-*.f64N/A

        \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\color{blue}{\ell \cdot 4}}{\frac{Om}{\sin ky}}, \frac{\ell}{\frac{Om}{\sin ky}}, 1\right)}}, \frac{1}{2}\right)} \]
      11. /-lowering-/.f64N/A

        \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\ell \cdot 4}{\color{blue}{\frac{Om}{\sin ky}}}, \frac{\ell}{\frac{Om}{\sin ky}}, 1\right)}}, \frac{1}{2}\right)} \]
      12. sin-lowering-sin.f64N/A

        \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\ell \cdot 4}{\frac{Om}{\color{blue}{\sin ky}}}, \frac{\ell}{\frac{Om}{\sin ky}}, 1\right)}}, \frac{1}{2}\right)} \]
      13. /-lowering-/.f64N/A

        \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\ell \cdot 4}{\frac{Om}{\sin ky}}, \color{blue}{\frac{\ell}{\frac{Om}{\sin ky}}}, 1\right)}}, \frac{1}{2}\right)} \]
      14. /-lowering-/.f64N/A

        \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\ell \cdot 4}{\frac{Om}{\sin ky}}, \frac{\ell}{\color{blue}{\frac{Om}{\sin ky}}}, 1\right)}}, \frac{1}{2}\right)} \]
      15. sin-lowering-sin.f6494.3

        \[\leadsto \sqrt{\mathsf{fma}\left(0.5, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\ell \cdot 4}{\frac{Om}{\sin ky}}, \frac{\ell}{\frac{Om}{\color{blue}{\sin ky}}}, 1\right)}}, 0.5\right)} \]
    7. Applied egg-rr94.3%

      \[\leadsto \sqrt{\mathsf{fma}\left(0.5, \sqrt{\frac{1}{\color{blue}{\mathsf{fma}\left(\frac{\ell \cdot 4}{\frac{Om}{\sin ky}}, \frac{\ell}{\frac{Om}{\sin ky}}, 1\right)}}}, 0.5\right)} \]
    8. Taylor expanded in ky around 0

      \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\ell \cdot 4}{\frac{Om}{\sin ky}}, \color{blue}{\frac{ky \cdot \ell}{Om}}, 1\right)}}, \frac{1}{2}\right)} \]
    9. Step-by-step derivation
      1. /-lowering-/.f64N/A

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

        \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\ell \cdot 4}{\frac{Om}{\sin ky}}, \frac{\color{blue}{\ell \cdot ky}}{Om}, 1\right)}}, \frac{1}{2}\right)} \]
      3. *-lowering-*.f6494.3

        \[\leadsto \sqrt{\mathsf{fma}\left(0.5, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\ell \cdot 4}{\frac{Om}{\sin ky}}, \frac{\color{blue}{\ell \cdot ky}}{Om}, 1\right)}}, 0.5\right)} \]
    10. Simplified94.3%

      \[\leadsto \sqrt{\mathsf{fma}\left(0.5, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\ell \cdot 4}{\frac{Om}{\sin ky}}, \color{blue}{\frac{\ell \cdot ky}{Om}}, 1\right)}}, 0.5\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification86.6%

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

Alternative 4: 79.9% accurate, 3.0× speedup?

\[\begin{array}{l} kx_m = \left|kx\right| \\ ky_m = \left|ky\right| \\ [l, Om, kx_m, ky_m] = \mathsf{sort}([l, Om, kx_m, ky_m])\\ \\ \begin{array}{l} \mathbf{if}\;\ell \leq 2 \cdot 10^{-177}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(0.5, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\ell \cdot 4}{Om}, \frac{\ell}{Om} \cdot \mathsf{fma}\left(-0.5, \cos \left(kx\_m + kx\_m\right), 0.5\right), 1\right)}}, 0.5\right)}\\ \mathbf{elif}\;\ell \leq 3.4 \cdot 10^{+130}:\\ \;\;\;\;\sqrt{0.5 + 0.5 \cdot \sqrt{\frac{1}{\mathsf{fma}\left(4, \frac{\mathsf{fma}\left(-0.5, \cos \left(ky\_m \cdot -2\right), 0.5\right) \cdot \left(\ell \cdot \ell\right)}{Om \cdot Om}, 1\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \end{array} \]
kx_m = (fabs.f64 kx)
ky_m = (fabs.f64 ky)
NOTE: l, Om, kx_m, and ky_m should be sorted in increasing order before calling this function.
(FPCore (l Om kx_m ky_m)
 :precision binary64
 (if (<= l 2e-177)
   (sqrt
    (fma
     0.5
     (sqrt
      (/
       1.0
       (fma
        (/ (* l 4.0) Om)
        (* (/ l Om) (fma -0.5 (cos (+ kx_m kx_m)) 0.5))
        1.0)))
     0.5))
   (if (<= l 3.4e+130)
     (sqrt
      (+
       0.5
       (*
        0.5
        (sqrt
         (/
          1.0
          (fma
           4.0
           (/ (* (fma -0.5 (cos (* ky_m -2.0)) 0.5) (* l l)) (* Om Om))
           1.0))))))
     (sqrt 0.5))))
kx_m = fabs(kx);
ky_m = fabs(ky);
assert(l < Om && Om < kx_m && kx_m < ky_m);
double code(double l, double Om, double kx_m, double ky_m) {
	double tmp;
	if (l <= 2e-177) {
		tmp = sqrt(fma(0.5, sqrt((1.0 / fma(((l * 4.0) / Om), ((l / Om) * fma(-0.5, cos((kx_m + kx_m)), 0.5)), 1.0))), 0.5));
	} else if (l <= 3.4e+130) {
		tmp = sqrt((0.5 + (0.5 * sqrt((1.0 / fma(4.0, ((fma(-0.5, cos((ky_m * -2.0)), 0.5) * (l * l)) / (Om * Om)), 1.0))))));
	} else {
		tmp = sqrt(0.5);
	}
	return tmp;
}
kx_m = abs(kx)
ky_m = abs(ky)
l, Om, kx_m, ky_m = sort([l, Om, kx_m, ky_m])
function code(l, Om, kx_m, ky_m)
	tmp = 0.0
	if (l <= 2e-177)
		tmp = sqrt(fma(0.5, sqrt(Float64(1.0 / fma(Float64(Float64(l * 4.0) / Om), Float64(Float64(l / Om) * fma(-0.5, cos(Float64(kx_m + kx_m)), 0.5)), 1.0))), 0.5));
	elseif (l <= 3.4e+130)
		tmp = sqrt(Float64(0.5 + Float64(0.5 * sqrt(Float64(1.0 / fma(4.0, Float64(Float64(fma(-0.5, cos(Float64(ky_m * -2.0)), 0.5) * Float64(l * l)) / Float64(Om * Om)), 1.0))))));
	else
		tmp = sqrt(0.5);
	end
	return tmp
end
kx_m = N[Abs[kx], $MachinePrecision]
ky_m = N[Abs[ky], $MachinePrecision]
NOTE: l, Om, kx_m, and ky_m should be sorted in increasing order before calling this function.
code[l_, Om_, kx$95$m_, ky$95$m_] := If[LessEqual[l, 2e-177], N[Sqrt[N[(0.5 * N[Sqrt[N[(1.0 / N[(N[(N[(l * 4.0), $MachinePrecision] / Om), $MachinePrecision] * N[(N[(l / Om), $MachinePrecision] * N[(-0.5 * N[Cos[N[(kx$95$m + kx$95$m), $MachinePrecision]], $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + 0.5), $MachinePrecision]], $MachinePrecision], If[LessEqual[l, 3.4e+130], N[Sqrt[N[(0.5 + N[(0.5 * N[Sqrt[N[(1.0 / N[(4.0 * N[(N[(N[(-0.5 * N[Cos[N[(ky$95$m * -2.0), $MachinePrecision]], $MachinePrecision] + 0.5), $MachinePrecision] * N[(l * l), $MachinePrecision]), $MachinePrecision] / N[(Om * Om), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[0.5], $MachinePrecision]]]
\begin{array}{l}
kx_m = \left|kx\right|
\\
ky_m = \left|ky\right|
\\
[l, Om, kx_m, ky_m] = \mathsf{sort}([l, Om, kx_m, ky_m])\\
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 2 \cdot 10^{-177}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(0.5, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\ell \cdot 4}{Om}, \frac{\ell}{Om} \cdot \mathsf{fma}\left(-0.5, \cos \left(kx\_m + kx\_m\right), 0.5\right), 1\right)}}, 0.5\right)}\\

\mathbf{elif}\;\ell \leq 3.4 \cdot 10^{+130}:\\
\;\;\;\;\sqrt{0.5 + 0.5 \cdot \sqrt{\frac{1}{\mathsf{fma}\left(4, \frac{\mathsf{fma}\left(-0.5, \cos \left(ky\_m \cdot -2\right), 0.5\right) \cdot \left(\ell \cdot \ell\right)}{Om \cdot Om}, 1\right)}}}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < 1.9999999999999999e-177

    1. Initial program 98.1%

      \[\sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in kx around 0

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

        \[\leadsto \sqrt{\frac{1}{2} \cdot \color{blue}{\left(\sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot {\sin ky}^{2}}{{Om}^{2}}}} + 1\right)}} \]
      2. distribute-lft-inN/A

        \[\leadsto \sqrt{\color{blue}{\frac{1}{2} \cdot \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot {\sin ky}^{2}}{{Om}^{2}}}} + \frac{1}{2} \cdot 1}} \]
      3. metadata-evalN/A

        \[\leadsto \sqrt{\frac{1}{2} \cdot \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot {\sin ky}^{2}}{{Om}^{2}}}} + \color{blue}{\frac{1}{2}}} \]
      4. accelerator-lowering-fma.f64N/A

        \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot {\sin ky}^{2}}{{Om}^{2}}}}, \frac{1}{2}\right)}} \]
    5. Simplified79.9%

      \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(0.5, \sqrt{\frac{1}{\mathsf{fma}\left(4 \cdot \left(\ell \cdot \ell\right), \frac{{\sin ky}^{2}}{Om \cdot Om}, 1\right)}}, 0.5\right)}} \]
    6. Applied egg-rr83.6%

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

    if 1.9999999999999999e-177 < l < 3.4000000000000001e130

    1. Initial program 100.0%

      \[\sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}}\right)} \]
    2. Add Preprocessing
    3. Applied egg-rr96.0%

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

      \[\leadsto \sqrt{\color{blue}{\frac{1}{2} \cdot \left(1 + \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot \left(\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}{{Om}^{2}}}}\right)}} \]
    5. Step-by-step derivation
      1. distribute-lft-inN/A

        \[\leadsto \sqrt{\color{blue}{\frac{1}{2} \cdot 1 + \frac{1}{2} \cdot \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot \left(\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}{{Om}^{2}}}}}} \]
      2. metadata-evalN/A

        \[\leadsto \sqrt{\color{blue}{\frac{1}{2}} + \frac{1}{2} \cdot \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot \left(\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}{{Om}^{2}}}}} \]
      3. +-lowering-+.f64N/A

        \[\leadsto \sqrt{\color{blue}{\frac{1}{2} + \frac{1}{2} \cdot \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot \left(\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}{{Om}^{2}}}}}} \]
      4. *-lowering-*.f64N/A

        \[\leadsto \sqrt{\frac{1}{2} + \color{blue}{\frac{1}{2} \cdot \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot \left(\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}{{Om}^{2}}}}}} \]
      5. sqrt-lowering-sqrt.f64N/A

        \[\leadsto \sqrt{\frac{1}{2} + \frac{1}{2} \cdot \color{blue}{\sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot \left(\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}{{Om}^{2}}}}}} \]
      6. /-lowering-/.f64N/A

        \[\leadsto \sqrt{\frac{1}{2} + \frac{1}{2} \cdot \sqrt{\color{blue}{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot \left(\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}{{Om}^{2}}}}}} \]
      7. +-commutativeN/A

        \[\leadsto \sqrt{\frac{1}{2} + \frac{1}{2} \cdot \sqrt{\frac{1}{\color{blue}{4 \cdot \frac{{\ell}^{2} \cdot \left(\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}{{Om}^{2}} + 1}}}} \]
      8. accelerator-lowering-fma.f64N/A

        \[\leadsto \sqrt{\frac{1}{2} + \frac{1}{2} \cdot \sqrt{\frac{1}{\color{blue}{\mathsf{fma}\left(4, \frac{{\ell}^{2} \cdot \left(\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}{{Om}^{2}}, 1\right)}}}} \]
    6. Simplified89.2%

      \[\leadsto \sqrt{\color{blue}{0.5 + 0.5 \cdot \sqrt{\frac{1}{\mathsf{fma}\left(4, \frac{\left(\ell \cdot \ell\right) \cdot \mathsf{fma}\left(-0.5, \cos \left(ky \cdot -2\right), 0.5\right)}{Om \cdot Om}, 1\right)}}}} \]

    if 3.4000000000000001e130 < l

    1. Initial program 88.1%

      \[\sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in l around inf

      \[\leadsto \sqrt{\color{blue}{\frac{1}{2}}} \]
    4. Step-by-step derivation
      1. Simplified87.1%

        \[\leadsto \sqrt{\color{blue}{0.5}} \]
    5. Recombined 3 regimes into one program.
    6. Final simplification85.4%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 2 \cdot 10^{-177}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(0.5, \sqrt{\frac{1}{\mathsf{fma}\left(\frac{\ell \cdot 4}{Om}, \frac{\ell}{Om} \cdot \mathsf{fma}\left(-0.5, \cos \left(kx + kx\right), 0.5\right), 1\right)}}, 0.5\right)}\\ \mathbf{elif}\;\ell \leq 3.4 \cdot 10^{+130}:\\ \;\;\;\;\sqrt{0.5 + 0.5 \cdot \sqrt{\frac{1}{\mathsf{fma}\left(4, \frac{\mathsf{fma}\left(-0.5, \cos \left(ky \cdot -2\right), 0.5\right) \cdot \left(\ell \cdot \ell\right)}{Om \cdot Om}, 1\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \]
    7. Add Preprocessing

    Alternative 5: 75.4% accurate, 3.0× speedup?

    \[\begin{array}{l} kx_m = \left|kx\right| \\ ky_m = \left|ky\right| \\ [l, Om, kx_m, ky_m] = \mathsf{sort}([l, Om, kx_m, ky_m])\\ \\ \begin{array}{l} \mathbf{if}\;\ell \leq 2 \cdot 10^{-177}:\\ \;\;\;\;1\\ \mathbf{elif}\;\ell \leq 1.28 \cdot 10^{+129}:\\ \;\;\;\;\sqrt{0.5 + 0.5 \cdot \sqrt{\frac{1}{\mathsf{fma}\left(4, \frac{\mathsf{fma}\left(-0.5, \cos \left(ky\_m \cdot -2\right), 0.5\right) \cdot \left(\ell \cdot \ell\right)}{Om \cdot Om}, 1\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \end{array} \]
    kx_m = (fabs.f64 kx)
    ky_m = (fabs.f64 ky)
    NOTE: l, Om, kx_m, and ky_m should be sorted in increasing order before calling this function.
    (FPCore (l Om kx_m ky_m)
     :precision binary64
     (if (<= l 2e-177)
       1.0
       (if (<= l 1.28e+129)
         (sqrt
          (+
           0.5
           (*
            0.5
            (sqrt
             (/
              1.0
              (fma
               4.0
               (/ (* (fma -0.5 (cos (* ky_m -2.0)) 0.5) (* l l)) (* Om Om))
               1.0))))))
         (sqrt 0.5))))
    kx_m = fabs(kx);
    ky_m = fabs(ky);
    assert(l < Om && Om < kx_m && kx_m < ky_m);
    double code(double l, double Om, double kx_m, double ky_m) {
    	double tmp;
    	if (l <= 2e-177) {
    		tmp = 1.0;
    	} else if (l <= 1.28e+129) {
    		tmp = sqrt((0.5 + (0.5 * sqrt((1.0 / fma(4.0, ((fma(-0.5, cos((ky_m * -2.0)), 0.5) * (l * l)) / (Om * Om)), 1.0))))));
    	} else {
    		tmp = sqrt(0.5);
    	}
    	return tmp;
    }
    
    kx_m = abs(kx)
    ky_m = abs(ky)
    l, Om, kx_m, ky_m = sort([l, Om, kx_m, ky_m])
    function code(l, Om, kx_m, ky_m)
    	tmp = 0.0
    	if (l <= 2e-177)
    		tmp = 1.0;
    	elseif (l <= 1.28e+129)
    		tmp = sqrt(Float64(0.5 + Float64(0.5 * sqrt(Float64(1.0 / fma(4.0, Float64(Float64(fma(-0.5, cos(Float64(ky_m * -2.0)), 0.5) * Float64(l * l)) / Float64(Om * Om)), 1.0))))));
    	else
    		tmp = sqrt(0.5);
    	end
    	return tmp
    end
    
    kx_m = N[Abs[kx], $MachinePrecision]
    ky_m = N[Abs[ky], $MachinePrecision]
    NOTE: l, Om, kx_m, and ky_m should be sorted in increasing order before calling this function.
    code[l_, Om_, kx$95$m_, ky$95$m_] := If[LessEqual[l, 2e-177], 1.0, If[LessEqual[l, 1.28e+129], N[Sqrt[N[(0.5 + N[(0.5 * N[Sqrt[N[(1.0 / N[(4.0 * N[(N[(N[(-0.5 * N[Cos[N[(ky$95$m * -2.0), $MachinePrecision]], $MachinePrecision] + 0.5), $MachinePrecision] * N[(l * l), $MachinePrecision]), $MachinePrecision] / N[(Om * Om), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[0.5], $MachinePrecision]]]
    
    \begin{array}{l}
    kx_m = \left|kx\right|
    \\
    ky_m = \left|ky\right|
    \\
    [l, Om, kx_m, ky_m] = \mathsf{sort}([l, Om, kx_m, ky_m])\\
    \\
    \begin{array}{l}
    \mathbf{if}\;\ell \leq 2 \cdot 10^{-177}:\\
    \;\;\;\;1\\
    
    \mathbf{elif}\;\ell \leq 1.28 \cdot 10^{+129}:\\
    \;\;\;\;\sqrt{0.5 + 0.5 \cdot \sqrt{\frac{1}{\mathsf{fma}\left(4, \frac{\mathsf{fma}\left(-0.5, \cos \left(ky\_m \cdot -2\right), 0.5\right) \cdot \left(\ell \cdot \ell\right)}{Om \cdot Om}, 1\right)}}}\\
    
    \mathbf{else}:\\
    \;\;\;\;\sqrt{0.5}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if l < 1.9999999999999999e-177

      1. Initial program 98.1%

        \[\sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}}\right)} \]
      2. Add Preprocessing
      3. Taylor expanded in l around 0

        \[\leadsto \sqrt{\color{blue}{1}} \]
      4. Step-by-step derivation
        1. Simplified70.6%

          \[\leadsto \sqrt{\color{blue}{1}} \]
        2. Step-by-step derivation
          1. metadata-eval70.6

            \[\leadsto \color{blue}{1} \]
        3. Applied egg-rr70.6%

          \[\leadsto \color{blue}{1} \]

        if 1.9999999999999999e-177 < l < 1.27999999999999994e129

        1. Initial program 100.0%

          \[\sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}}\right)} \]
        2. Add Preprocessing
        3. Applied egg-rr96.0%

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

          \[\leadsto \sqrt{\color{blue}{\frac{1}{2} \cdot \left(1 + \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot \left(\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}{{Om}^{2}}}}\right)}} \]
        5. Step-by-step derivation
          1. distribute-lft-inN/A

            \[\leadsto \sqrt{\color{blue}{\frac{1}{2} \cdot 1 + \frac{1}{2} \cdot \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot \left(\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}{{Om}^{2}}}}}} \]
          2. metadata-evalN/A

            \[\leadsto \sqrt{\color{blue}{\frac{1}{2}} + \frac{1}{2} \cdot \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot \left(\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}{{Om}^{2}}}}} \]
          3. +-lowering-+.f64N/A

            \[\leadsto \sqrt{\color{blue}{\frac{1}{2} + \frac{1}{2} \cdot \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot \left(\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}{{Om}^{2}}}}}} \]
          4. *-lowering-*.f64N/A

            \[\leadsto \sqrt{\frac{1}{2} + \color{blue}{\frac{1}{2} \cdot \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot \left(\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}{{Om}^{2}}}}}} \]
          5. sqrt-lowering-sqrt.f64N/A

            \[\leadsto \sqrt{\frac{1}{2} + \frac{1}{2} \cdot \color{blue}{\sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot \left(\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}{{Om}^{2}}}}}} \]
          6. /-lowering-/.f64N/A

            \[\leadsto \sqrt{\frac{1}{2} + \frac{1}{2} \cdot \sqrt{\color{blue}{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot \left(\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}{{Om}^{2}}}}}} \]
          7. +-commutativeN/A

            \[\leadsto \sqrt{\frac{1}{2} + \frac{1}{2} \cdot \sqrt{\frac{1}{\color{blue}{4 \cdot \frac{{\ell}^{2} \cdot \left(\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}{{Om}^{2}} + 1}}}} \]
          8. accelerator-lowering-fma.f64N/A

            \[\leadsto \sqrt{\frac{1}{2} + \frac{1}{2} \cdot \sqrt{\frac{1}{\color{blue}{\mathsf{fma}\left(4, \frac{{\ell}^{2} \cdot \left(\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}{{Om}^{2}}, 1\right)}}}} \]
        6. Simplified89.2%

          \[\leadsto \sqrt{\color{blue}{0.5 + 0.5 \cdot \sqrt{\frac{1}{\mathsf{fma}\left(4, \frac{\left(\ell \cdot \ell\right) \cdot \mathsf{fma}\left(-0.5, \cos \left(ky \cdot -2\right), 0.5\right)}{Om \cdot Om}, 1\right)}}}} \]

        if 1.27999999999999994e129 < l

        1. Initial program 88.1%

          \[\sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}}\right)} \]
        2. Add Preprocessing
        3. Taylor expanded in l around inf

          \[\leadsto \sqrt{\color{blue}{\frac{1}{2}}} \]
        4. Step-by-step derivation
          1. Simplified87.1%

            \[\leadsto \sqrt{\color{blue}{0.5}} \]
        5. Recombined 3 regimes into one program.
        6. Final simplification77.4%

          \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 2 \cdot 10^{-177}:\\ \;\;\;\;1\\ \mathbf{elif}\;\ell \leq 1.28 \cdot 10^{+129}:\\ \;\;\;\;\sqrt{0.5 + 0.5 \cdot \sqrt{\frac{1}{\mathsf{fma}\left(4, \frac{\mathsf{fma}\left(-0.5, \cos \left(ky \cdot -2\right), 0.5\right) \cdot \left(\ell \cdot \ell\right)}{Om \cdot Om}, 1\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \]
        7. Add Preprocessing

        Alternative 6: 71.9% accurate, 6.9× speedup?

        \[\begin{array}{l} kx_m = \left|kx\right| \\ ky_m = \left|ky\right| \\ [l, Om, kx_m, ky_m] = \mathsf{sort}([l, Om, kx_m, ky_m])\\ \\ \begin{array}{l} \mathbf{if}\;\ell \leq 2 \cdot 10^{-30}:\\ \;\;\;\;1\\ \mathbf{elif}\;\ell \leq 6.5 \cdot 10^{+134}:\\ \;\;\;\;\sqrt{0.5 + \frac{0.5}{\sqrt{\mathsf{fma}\left(\ell \cdot \left(\ell \cdot 4\right), \frac{ky\_m \cdot ky\_m}{Om \cdot Om}, 1\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \end{array} \]
        kx_m = (fabs.f64 kx)
        ky_m = (fabs.f64 ky)
        NOTE: l, Om, kx_m, and ky_m should be sorted in increasing order before calling this function.
        (FPCore (l Om kx_m ky_m)
         :precision binary64
         (if (<= l 2e-30)
           1.0
           (if (<= l 6.5e+134)
             (sqrt
              (+
               0.5
               (/ 0.5 (sqrt (fma (* l (* l 4.0)) (/ (* ky_m ky_m) (* Om Om)) 1.0)))))
             (sqrt 0.5))))
        kx_m = fabs(kx);
        ky_m = fabs(ky);
        assert(l < Om && Om < kx_m && kx_m < ky_m);
        double code(double l, double Om, double kx_m, double ky_m) {
        	double tmp;
        	if (l <= 2e-30) {
        		tmp = 1.0;
        	} else if (l <= 6.5e+134) {
        		tmp = sqrt((0.5 + (0.5 / sqrt(fma((l * (l * 4.0)), ((ky_m * ky_m) / (Om * Om)), 1.0)))));
        	} else {
        		tmp = sqrt(0.5);
        	}
        	return tmp;
        }
        
        kx_m = abs(kx)
        ky_m = abs(ky)
        l, Om, kx_m, ky_m = sort([l, Om, kx_m, ky_m])
        function code(l, Om, kx_m, ky_m)
        	tmp = 0.0
        	if (l <= 2e-30)
        		tmp = 1.0;
        	elseif (l <= 6.5e+134)
        		tmp = sqrt(Float64(0.5 + Float64(0.5 / sqrt(fma(Float64(l * Float64(l * 4.0)), Float64(Float64(ky_m * ky_m) / Float64(Om * Om)), 1.0)))));
        	else
        		tmp = sqrt(0.5);
        	end
        	return tmp
        end
        
        kx_m = N[Abs[kx], $MachinePrecision]
        ky_m = N[Abs[ky], $MachinePrecision]
        NOTE: l, Om, kx_m, and ky_m should be sorted in increasing order before calling this function.
        code[l_, Om_, kx$95$m_, ky$95$m_] := If[LessEqual[l, 2e-30], 1.0, If[LessEqual[l, 6.5e+134], N[Sqrt[N[(0.5 + N[(0.5 / N[Sqrt[N[(N[(l * N[(l * 4.0), $MachinePrecision]), $MachinePrecision] * N[(N[(ky$95$m * ky$95$m), $MachinePrecision] / N[(Om * Om), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[0.5], $MachinePrecision]]]
        
        \begin{array}{l}
        kx_m = \left|kx\right|
        \\
        ky_m = \left|ky\right|
        \\
        [l, Om, kx_m, ky_m] = \mathsf{sort}([l, Om, kx_m, ky_m])\\
        \\
        \begin{array}{l}
        \mathbf{if}\;\ell \leq 2 \cdot 10^{-30}:\\
        \;\;\;\;1\\
        
        \mathbf{elif}\;\ell \leq 6.5 \cdot 10^{+134}:\\
        \;\;\;\;\sqrt{0.5 + \frac{0.5}{\sqrt{\mathsf{fma}\left(\ell \cdot \left(\ell \cdot 4\right), \frac{ky\_m \cdot ky\_m}{Om \cdot Om}, 1\right)}}}\\
        
        \mathbf{else}:\\
        \;\;\;\;\sqrt{0.5}\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 3 regimes
        2. if l < 2e-30

          1. Initial program 98.4%

            \[\sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}}\right)} \]
          2. Add Preprocessing
          3. Taylor expanded in l around 0

            \[\leadsto \sqrt{\color{blue}{1}} \]
          4. Step-by-step derivation
            1. Simplified73.4%

              \[\leadsto \sqrt{\color{blue}{1}} \]
            2. Step-by-step derivation
              1. metadata-eval73.4

                \[\leadsto \color{blue}{1} \]
            3. Applied egg-rr73.4%

              \[\leadsto \color{blue}{1} \]

            if 2e-30 < l < 6.5e134

            1. Initial program 97.1%

              \[\sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}}\right)} \]
            2. Add Preprocessing
            3. Taylor expanded in kx around 0

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

                \[\leadsto \sqrt{\frac{1}{2} \cdot \color{blue}{\left(\sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot {\sin ky}^{2}}{{Om}^{2}}}} + 1\right)}} \]
              2. distribute-lft-inN/A

                \[\leadsto \sqrt{\color{blue}{\frac{1}{2} \cdot \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot {\sin ky}^{2}}{{Om}^{2}}}} + \frac{1}{2} \cdot 1}} \]
              3. metadata-evalN/A

                \[\leadsto \sqrt{\frac{1}{2} \cdot \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot {\sin ky}^{2}}{{Om}^{2}}}} + \color{blue}{\frac{1}{2}}} \]
              4. accelerator-lowering-fma.f64N/A

                \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot {\sin ky}^{2}}{{Om}^{2}}}}, \frac{1}{2}\right)}} \]
            5. Simplified84.1%

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

              \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\mathsf{fma}\left(4 \cdot \left(\ell \cdot \ell\right), \color{blue}{\frac{{ky}^{2}}{{Om}^{2}}}, 1\right)}}, \frac{1}{2}\right)} \]
            7. Step-by-step derivation
              1. /-lowering-/.f64N/A

                \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\mathsf{fma}\left(4 \cdot \left(\ell \cdot \ell\right), \color{blue}{\frac{{ky}^{2}}{{Om}^{2}}}, 1\right)}}, \frac{1}{2}\right)} \]
              2. unpow2N/A

                \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\mathsf{fma}\left(4 \cdot \left(\ell \cdot \ell\right), \frac{\color{blue}{ky \cdot ky}}{{Om}^{2}}, 1\right)}}, \frac{1}{2}\right)} \]
              3. *-lowering-*.f64N/A

                \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\mathsf{fma}\left(4 \cdot \left(\ell \cdot \ell\right), \frac{\color{blue}{ky \cdot ky}}{{Om}^{2}}, 1\right)}}, \frac{1}{2}\right)} \]
              4. unpow2N/A

                \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\mathsf{fma}\left(4 \cdot \left(\ell \cdot \ell\right), \frac{ky \cdot ky}{\color{blue}{Om \cdot Om}}, 1\right)}}, \frac{1}{2}\right)} \]
              5. *-lowering-*.f6479.0

                \[\leadsto \sqrt{\mathsf{fma}\left(0.5, \sqrt{\frac{1}{\mathsf{fma}\left(4 \cdot \left(\ell \cdot \ell\right), \frac{ky \cdot ky}{\color{blue}{Om \cdot Om}}, 1\right)}}, 0.5\right)} \]
            8. Simplified79.0%

              \[\leadsto \sqrt{\mathsf{fma}\left(0.5, \sqrt{\frac{1}{\mathsf{fma}\left(4 \cdot \left(\ell \cdot \ell\right), \color{blue}{\frac{ky \cdot ky}{Om \cdot Om}}, 1\right)}}, 0.5\right)} \]
            9. Step-by-step derivation
              1. +-lowering-+.f64N/A

                \[\leadsto \sqrt{\color{blue}{\frac{1}{2} \cdot \sqrt{\frac{1}{\left(4 \cdot \left(\ell \cdot \ell\right)\right) \cdot \frac{ky \cdot ky}{Om \cdot Om} + 1}} + \frac{1}{2}}} \]
            10. Applied egg-rr79.0%

              \[\leadsto \sqrt{\color{blue}{\frac{0.5}{\sqrt{\mathsf{fma}\left(\ell \cdot \left(\ell \cdot 4\right), \frac{ky \cdot ky}{Om \cdot Om}, 1\right)}} + 0.5}} \]

            if 6.5e134 < l

            1. Initial program 89.7%

              \[\sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}}\right)} \]
            2. Add Preprocessing
            3. Taylor expanded in l around inf

              \[\leadsto \sqrt{\color{blue}{\frac{1}{2}}} \]
            4. Step-by-step derivation
              1. Simplified88.2%

                \[\leadsto \sqrt{\color{blue}{0.5}} \]
            5. Recombined 3 regimes into one program.
            6. Final simplification76.4%

              \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 2 \cdot 10^{-30}:\\ \;\;\;\;1\\ \mathbf{elif}\;\ell \leq 6.5 \cdot 10^{+134}:\\ \;\;\;\;\sqrt{0.5 + \frac{0.5}{\sqrt{\mathsf{fma}\left(\ell \cdot \left(\ell \cdot 4\right), \frac{ky \cdot ky}{Om \cdot Om}, 1\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \]
            7. Add Preprocessing

            Alternative 7: 71.8% accurate, 7.8× speedup?

            \[\begin{array}{l} kx_m = \left|kx\right| \\ ky_m = \left|ky\right| \\ [l, Om, kx_m, ky_m] = \mathsf{sort}([l, Om, kx_m, ky_m])\\ \\ \begin{array}{l} \mathbf{if}\;\ell \leq 2 \cdot 10^{-30}:\\ \;\;\;\;1\\ \mathbf{elif}\;\ell \leq 1.25 \cdot 10^{+135}:\\ \;\;\;\;\sqrt{0.5 + \frac{0.5}{\mathsf{fma}\left(2, \left(ky\_m \cdot ky\_m\right) \cdot \frac{\ell \cdot \ell}{Om \cdot Om}, 1\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \end{array} \]
            kx_m = (fabs.f64 kx)
            ky_m = (fabs.f64 ky)
            NOTE: l, Om, kx_m, and ky_m should be sorted in increasing order before calling this function.
            (FPCore (l Om kx_m ky_m)
             :precision binary64
             (if (<= l 2e-30)
               1.0
               (if (<= l 1.25e+135)
                 (sqrt
                  (+ 0.5 (/ 0.5 (fma 2.0 (* (* ky_m ky_m) (/ (* l l) (* Om Om))) 1.0))))
                 (sqrt 0.5))))
            kx_m = fabs(kx);
            ky_m = fabs(ky);
            assert(l < Om && Om < kx_m && kx_m < ky_m);
            double code(double l, double Om, double kx_m, double ky_m) {
            	double tmp;
            	if (l <= 2e-30) {
            		tmp = 1.0;
            	} else if (l <= 1.25e+135) {
            		tmp = sqrt((0.5 + (0.5 / fma(2.0, ((ky_m * ky_m) * ((l * l) / (Om * Om))), 1.0))));
            	} else {
            		tmp = sqrt(0.5);
            	}
            	return tmp;
            }
            
            kx_m = abs(kx)
            ky_m = abs(ky)
            l, Om, kx_m, ky_m = sort([l, Om, kx_m, ky_m])
            function code(l, Om, kx_m, ky_m)
            	tmp = 0.0
            	if (l <= 2e-30)
            		tmp = 1.0;
            	elseif (l <= 1.25e+135)
            		tmp = sqrt(Float64(0.5 + Float64(0.5 / fma(2.0, Float64(Float64(ky_m * ky_m) * Float64(Float64(l * l) / Float64(Om * Om))), 1.0))));
            	else
            		tmp = sqrt(0.5);
            	end
            	return tmp
            end
            
            kx_m = N[Abs[kx], $MachinePrecision]
            ky_m = N[Abs[ky], $MachinePrecision]
            NOTE: l, Om, kx_m, and ky_m should be sorted in increasing order before calling this function.
            code[l_, Om_, kx$95$m_, ky$95$m_] := If[LessEqual[l, 2e-30], 1.0, If[LessEqual[l, 1.25e+135], N[Sqrt[N[(0.5 + N[(0.5 / N[(2.0 * N[(N[(ky$95$m * ky$95$m), $MachinePrecision] * N[(N[(l * l), $MachinePrecision] / N[(Om * Om), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[0.5], $MachinePrecision]]]
            
            \begin{array}{l}
            kx_m = \left|kx\right|
            \\
            ky_m = \left|ky\right|
            \\
            [l, Om, kx_m, ky_m] = \mathsf{sort}([l, Om, kx_m, ky_m])\\
            \\
            \begin{array}{l}
            \mathbf{if}\;\ell \leq 2 \cdot 10^{-30}:\\
            \;\;\;\;1\\
            
            \mathbf{elif}\;\ell \leq 1.25 \cdot 10^{+135}:\\
            \;\;\;\;\sqrt{0.5 + \frac{0.5}{\mathsf{fma}\left(2, \left(ky\_m \cdot ky\_m\right) \cdot \frac{\ell \cdot \ell}{Om \cdot Om}, 1\right)}}\\
            
            \mathbf{else}:\\
            \;\;\;\;\sqrt{0.5}\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 3 regimes
            2. if l < 2e-30

              1. Initial program 98.4%

                \[\sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}}\right)} \]
              2. Add Preprocessing
              3. Taylor expanded in l around 0

                \[\leadsto \sqrt{\color{blue}{1}} \]
              4. Step-by-step derivation
                1. Simplified73.4%

                  \[\leadsto \sqrt{\color{blue}{1}} \]
                2. Step-by-step derivation
                  1. metadata-eval73.4

                    \[\leadsto \color{blue}{1} \]
                3. Applied egg-rr73.4%

                  \[\leadsto \color{blue}{1} \]

                if 2e-30 < l < 1.25000000000000007e135

                1. Initial program 97.1%

                  \[\sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}}\right)} \]
                2. Add Preprocessing
                3. Taylor expanded in kx around 0

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

                    \[\leadsto \sqrt{\frac{1}{2} \cdot \color{blue}{\left(\sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot {\sin ky}^{2}}{{Om}^{2}}}} + 1\right)}} \]
                  2. distribute-lft-inN/A

                    \[\leadsto \sqrt{\color{blue}{\frac{1}{2} \cdot \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot {\sin ky}^{2}}{{Om}^{2}}}} + \frac{1}{2} \cdot 1}} \]
                  3. metadata-evalN/A

                    \[\leadsto \sqrt{\frac{1}{2} \cdot \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot {\sin ky}^{2}}{{Om}^{2}}}} + \color{blue}{\frac{1}{2}}} \]
                  4. accelerator-lowering-fma.f64N/A

                    \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{1 + 4 \cdot \frac{{\ell}^{2} \cdot {\sin ky}^{2}}{{Om}^{2}}}}, \frac{1}{2}\right)}} \]
                5. Simplified84.1%

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

                  \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\mathsf{fma}\left(4 \cdot \left(\ell \cdot \ell\right), \color{blue}{\frac{{ky}^{2}}{{Om}^{2}}}, 1\right)}}, \frac{1}{2}\right)} \]
                7. Step-by-step derivation
                  1. /-lowering-/.f64N/A

                    \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\mathsf{fma}\left(4 \cdot \left(\ell \cdot \ell\right), \color{blue}{\frac{{ky}^{2}}{{Om}^{2}}}, 1\right)}}, \frac{1}{2}\right)} \]
                  2. unpow2N/A

                    \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\mathsf{fma}\left(4 \cdot \left(\ell \cdot \ell\right), \frac{\color{blue}{ky \cdot ky}}{{Om}^{2}}, 1\right)}}, \frac{1}{2}\right)} \]
                  3. *-lowering-*.f64N/A

                    \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\mathsf{fma}\left(4 \cdot \left(\ell \cdot \ell\right), \frac{\color{blue}{ky \cdot ky}}{{Om}^{2}}, 1\right)}}, \frac{1}{2}\right)} \]
                  4. unpow2N/A

                    \[\leadsto \sqrt{\mathsf{fma}\left(\frac{1}{2}, \sqrt{\frac{1}{\mathsf{fma}\left(4 \cdot \left(\ell \cdot \ell\right), \frac{ky \cdot ky}{\color{blue}{Om \cdot Om}}, 1\right)}}, \frac{1}{2}\right)} \]
                  5. *-lowering-*.f6479.0

                    \[\leadsto \sqrt{\mathsf{fma}\left(0.5, \sqrt{\frac{1}{\mathsf{fma}\left(4 \cdot \left(\ell \cdot \ell\right), \frac{ky \cdot ky}{\color{blue}{Om \cdot Om}}, 1\right)}}, 0.5\right)} \]
                8. Simplified79.0%

                  \[\leadsto \sqrt{\mathsf{fma}\left(0.5, \sqrt{\frac{1}{\mathsf{fma}\left(4 \cdot \left(\ell \cdot \ell\right), \color{blue}{\frac{ky \cdot ky}{Om \cdot Om}}, 1\right)}}, 0.5\right)} \]
                9. Step-by-step derivation
                  1. +-lowering-+.f64N/A

                    \[\leadsto \sqrt{\color{blue}{\frac{1}{2} \cdot \sqrt{\frac{1}{\left(4 \cdot \left(\ell \cdot \ell\right)\right) \cdot \frac{ky \cdot ky}{Om \cdot Om} + 1}} + \frac{1}{2}}} \]
                10. Applied egg-rr79.0%

                  \[\leadsto \sqrt{\color{blue}{\frac{0.5}{\sqrt{\mathsf{fma}\left(\ell \cdot \left(\ell \cdot 4\right), \frac{ky \cdot ky}{Om \cdot Om}, 1\right)}} + 0.5}} \]
                11. Taylor expanded in l around 0

                  \[\leadsto \sqrt{\frac{\frac{1}{2}}{\color{blue}{1 + 2 \cdot \frac{{ky}^{2} \cdot {\ell}^{2}}{{Om}^{2}}}} + \frac{1}{2}} \]
                12. Step-by-step derivation
                  1. +-commutativeN/A

                    \[\leadsto \sqrt{\frac{\frac{1}{2}}{\color{blue}{2 \cdot \frac{{ky}^{2} \cdot {\ell}^{2}}{{Om}^{2}} + 1}} + \frac{1}{2}} \]
                  2. accelerator-lowering-fma.f64N/A

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

                    \[\leadsto \sqrt{\frac{\frac{1}{2}}{\mathsf{fma}\left(2, \color{blue}{{ky}^{2} \cdot \frac{{\ell}^{2}}{{Om}^{2}}}, 1\right)} + \frac{1}{2}} \]
                  4. *-lowering-*.f64N/A

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

                    \[\leadsto \sqrt{\frac{\frac{1}{2}}{\mathsf{fma}\left(2, \color{blue}{\left(ky \cdot ky\right)} \cdot \frac{{\ell}^{2}}{{Om}^{2}}, 1\right)} + \frac{1}{2}} \]
                  6. *-lowering-*.f64N/A

                    \[\leadsto \sqrt{\frac{\frac{1}{2}}{\mathsf{fma}\left(2, \color{blue}{\left(ky \cdot ky\right)} \cdot \frac{{\ell}^{2}}{{Om}^{2}}, 1\right)} + \frac{1}{2}} \]
                  7. /-lowering-/.f64N/A

                    \[\leadsto \sqrt{\frac{\frac{1}{2}}{\mathsf{fma}\left(2, \left(ky \cdot ky\right) \cdot \color{blue}{\frac{{\ell}^{2}}{{Om}^{2}}}, 1\right)} + \frac{1}{2}} \]
                  8. unpow2N/A

                    \[\leadsto \sqrt{\frac{\frac{1}{2}}{\mathsf{fma}\left(2, \left(ky \cdot ky\right) \cdot \frac{\color{blue}{\ell \cdot \ell}}{{Om}^{2}}, 1\right)} + \frac{1}{2}} \]
                  9. *-lowering-*.f64N/A

                    \[\leadsto \sqrt{\frac{\frac{1}{2}}{\mathsf{fma}\left(2, \left(ky \cdot ky\right) \cdot \frac{\color{blue}{\ell \cdot \ell}}{{Om}^{2}}, 1\right)} + \frac{1}{2}} \]
                  10. unpow2N/A

                    \[\leadsto \sqrt{\frac{\frac{1}{2}}{\mathsf{fma}\left(2, \left(ky \cdot ky\right) \cdot \frac{\ell \cdot \ell}{\color{blue}{Om \cdot Om}}, 1\right)} + \frac{1}{2}} \]
                  11. *-lowering-*.f6479.0

                    \[\leadsto \sqrt{\frac{0.5}{\mathsf{fma}\left(2, \left(ky \cdot ky\right) \cdot \frac{\ell \cdot \ell}{\color{blue}{Om \cdot Om}}, 1\right)} + 0.5} \]
                13. Simplified79.0%

                  \[\leadsto \sqrt{\frac{0.5}{\color{blue}{\mathsf{fma}\left(2, \left(ky \cdot ky\right) \cdot \frac{\ell \cdot \ell}{Om \cdot Om}, 1\right)}} + 0.5} \]

                if 1.25000000000000007e135 < l

                1. Initial program 89.7%

                  \[\sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}}\right)} \]
                2. Add Preprocessing
                3. Taylor expanded in l around inf

                  \[\leadsto \sqrt{\color{blue}{\frac{1}{2}}} \]
                4. Step-by-step derivation
                  1. Simplified88.2%

                    \[\leadsto \sqrt{\color{blue}{0.5}} \]
                5. Recombined 3 regimes into one program.
                6. Final simplification76.4%

                  \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 2 \cdot 10^{-30}:\\ \;\;\;\;1\\ \mathbf{elif}\;\ell \leq 1.25 \cdot 10^{+135}:\\ \;\;\;\;\sqrt{0.5 + \frac{0.5}{\mathsf{fma}\left(2, \left(ky \cdot ky\right) \cdot \frac{\ell \cdot \ell}{Om \cdot Om}, 1\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \]
                7. Add Preprocessing

                Alternative 8: 67.7% accurate, 34.1× speedup?

                \[\begin{array}{l} kx_m = \left|kx\right| \\ ky_m = \left|ky\right| \\ [l, Om, kx_m, ky_m] = \mathsf{sort}([l, Om, kx_m, ky_m])\\ \\ \begin{array}{l} \mathbf{if}\;Om \leq 2.2 \cdot 10^{-85}:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
                kx_m = (fabs.f64 kx)
                ky_m = (fabs.f64 ky)
                NOTE: l, Om, kx_m, and ky_m should be sorted in increasing order before calling this function.
                (FPCore (l Om kx_m ky_m)
                 :precision binary64
                 (if (<= Om 2.2e-85) (sqrt 0.5) 1.0))
                kx_m = fabs(kx);
                ky_m = fabs(ky);
                assert(l < Om && Om < kx_m && kx_m < ky_m);
                double code(double l, double Om, double kx_m, double ky_m) {
                	double tmp;
                	if (Om <= 2.2e-85) {
                		tmp = sqrt(0.5);
                	} else {
                		tmp = 1.0;
                	}
                	return tmp;
                }
                
                kx_m = abs(kx)
                ky_m = abs(ky)
                NOTE: l, Om, kx_m, and ky_m should be sorted in increasing order before calling this function.
                real(8) function code(l, om, kx_m, ky_m)
                    real(8), intent (in) :: l
                    real(8), intent (in) :: om
                    real(8), intent (in) :: kx_m
                    real(8), intent (in) :: ky_m
                    real(8) :: tmp
                    if (om <= 2.2d-85) then
                        tmp = sqrt(0.5d0)
                    else
                        tmp = 1.0d0
                    end if
                    code = tmp
                end function
                
                kx_m = Math.abs(kx);
                ky_m = Math.abs(ky);
                assert l < Om && Om < kx_m && kx_m < ky_m;
                public static double code(double l, double Om, double kx_m, double ky_m) {
                	double tmp;
                	if (Om <= 2.2e-85) {
                		tmp = Math.sqrt(0.5);
                	} else {
                		tmp = 1.0;
                	}
                	return tmp;
                }
                
                kx_m = math.fabs(kx)
                ky_m = math.fabs(ky)
                [l, Om, kx_m, ky_m] = sort([l, Om, kx_m, ky_m])
                def code(l, Om, kx_m, ky_m):
                	tmp = 0
                	if Om <= 2.2e-85:
                		tmp = math.sqrt(0.5)
                	else:
                		tmp = 1.0
                	return tmp
                
                kx_m = abs(kx)
                ky_m = abs(ky)
                l, Om, kx_m, ky_m = sort([l, Om, kx_m, ky_m])
                function code(l, Om, kx_m, ky_m)
                	tmp = 0.0
                	if (Om <= 2.2e-85)
                		tmp = sqrt(0.5);
                	else
                		tmp = 1.0;
                	end
                	return tmp
                end
                
                kx_m = abs(kx);
                ky_m = abs(ky);
                l, Om, kx_m, ky_m = num2cell(sort([l, Om, kx_m, ky_m])){:}
                function tmp_2 = code(l, Om, kx_m, ky_m)
                	tmp = 0.0;
                	if (Om <= 2.2e-85)
                		tmp = sqrt(0.5);
                	else
                		tmp = 1.0;
                	end
                	tmp_2 = tmp;
                end
                
                kx_m = N[Abs[kx], $MachinePrecision]
                ky_m = N[Abs[ky], $MachinePrecision]
                NOTE: l, Om, kx_m, and ky_m should be sorted in increasing order before calling this function.
                code[l_, Om_, kx$95$m_, ky$95$m_] := If[LessEqual[Om, 2.2e-85], N[Sqrt[0.5], $MachinePrecision], 1.0]
                
                \begin{array}{l}
                kx_m = \left|kx\right|
                \\
                ky_m = \left|ky\right|
                \\
                [l, Om, kx_m, ky_m] = \mathsf{sort}([l, Om, kx_m, ky_m])\\
                \\
                \begin{array}{l}
                \mathbf{if}\;Om \leq 2.2 \cdot 10^{-85}:\\
                \;\;\;\;\sqrt{0.5}\\
                
                \mathbf{else}:\\
                \;\;\;\;1\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 2 regimes
                2. if Om < 2.2e-85

                  1. Initial program 96.2%

                    \[\sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}}\right)} \]
                  2. Add Preprocessing
                  3. Taylor expanded in l around inf

                    \[\leadsto \sqrt{\color{blue}{\frac{1}{2}}} \]
                  4. Step-by-step derivation
                    1. Simplified63.4%

                      \[\leadsto \sqrt{\color{blue}{0.5}} \]

                    if 2.2e-85 < Om

                    1. Initial program 98.6%

                      \[\sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}}\right)} \]
                    2. Add Preprocessing
                    3. Taylor expanded in l around 0

                      \[\leadsto \sqrt{\color{blue}{1}} \]
                    4. Step-by-step derivation
                      1. Simplified81.4%

                        \[\leadsto \sqrt{\color{blue}{1}} \]
                      2. Step-by-step derivation
                        1. metadata-eval81.4

                          \[\leadsto \color{blue}{1} \]
                      3. Applied egg-rr81.4%

                        \[\leadsto \color{blue}{1} \]
                    5. Recombined 2 regimes into one program.
                    6. Add Preprocessing

                    Alternative 9: 62.3% accurate, 581.0× speedup?

                    \[\begin{array}{l} kx_m = \left|kx\right| \\ ky_m = \left|ky\right| \\ [l, Om, kx_m, ky_m] = \mathsf{sort}([l, Om, kx_m, ky_m])\\ \\ 1 \end{array} \]
                    kx_m = (fabs.f64 kx)
                    ky_m = (fabs.f64 ky)
                    NOTE: l, Om, kx_m, and ky_m should be sorted in increasing order before calling this function.
                    (FPCore (l Om kx_m ky_m) :precision binary64 1.0)
                    kx_m = fabs(kx);
                    ky_m = fabs(ky);
                    assert(l < Om && Om < kx_m && kx_m < ky_m);
                    double code(double l, double Om, double kx_m, double ky_m) {
                    	return 1.0;
                    }
                    
                    kx_m = abs(kx)
                    ky_m = abs(ky)
                    NOTE: l, Om, kx_m, and ky_m should be sorted in increasing order before calling this function.
                    real(8) function code(l, om, kx_m, ky_m)
                        real(8), intent (in) :: l
                        real(8), intent (in) :: om
                        real(8), intent (in) :: kx_m
                        real(8), intent (in) :: ky_m
                        code = 1.0d0
                    end function
                    
                    kx_m = Math.abs(kx);
                    ky_m = Math.abs(ky);
                    assert l < Om && Om < kx_m && kx_m < ky_m;
                    public static double code(double l, double Om, double kx_m, double ky_m) {
                    	return 1.0;
                    }
                    
                    kx_m = math.fabs(kx)
                    ky_m = math.fabs(ky)
                    [l, Om, kx_m, ky_m] = sort([l, Om, kx_m, ky_m])
                    def code(l, Om, kx_m, ky_m):
                    	return 1.0
                    
                    kx_m = abs(kx)
                    ky_m = abs(ky)
                    l, Om, kx_m, ky_m = sort([l, Om, kx_m, ky_m])
                    function code(l, Om, kx_m, ky_m)
                    	return 1.0
                    end
                    
                    kx_m = abs(kx);
                    ky_m = abs(ky);
                    l, Om, kx_m, ky_m = num2cell(sort([l, Om, kx_m, ky_m])){:}
                    function tmp = code(l, Om, kx_m, ky_m)
                    	tmp = 1.0;
                    end
                    
                    kx_m = N[Abs[kx], $MachinePrecision]
                    ky_m = N[Abs[ky], $MachinePrecision]
                    NOTE: l, Om, kx_m, and ky_m should be sorted in increasing order before calling this function.
                    code[l_, Om_, kx$95$m_, ky$95$m_] := 1.0
                    
                    \begin{array}{l}
                    kx_m = \left|kx\right|
                    \\
                    ky_m = \left|ky\right|
                    \\
                    [l, Om, kx_m, ky_m] = \mathsf{sort}([l, Om, kx_m, ky_m])\\
                    \\
                    1
                    \end{array}
                    
                    Derivation
                    1. Initial program 96.9%

                      \[\sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}}\right)} \]
                    2. Add Preprocessing
                    3. Taylor expanded in l around 0

                      \[\leadsto \sqrt{\color{blue}{1}} \]
                    4. Step-by-step derivation
                      1. Simplified62.8%

                        \[\leadsto \sqrt{\color{blue}{1}} \]
                      2. Step-by-step derivation
                        1. metadata-eval62.8

                          \[\leadsto \color{blue}{1} \]
                      3. Applied egg-rr62.8%

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

                      Reproduce

                      ?
                      herbie shell --seed 2024197 
                      (FPCore (l Om kx ky)
                        :name "Toniolo and Linder, Equation (3a)"
                        :precision binary64
                        (sqrt (* (/ 1.0 2.0) (+ 1.0 (/ 1.0 (sqrt (+ 1.0 (* (pow (/ (* 2.0 l) Om) 2.0) (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0))))))))))