Toniolo and Linder, Equation (3a)

Percentage Accurate: 98.3% → 99.7%
Time: 12.7s
Alternatives: 5
Speedup: 2.3×

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 5 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.3% 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.7% accurate, 2.3× speedup?

\[\begin{array}{l} kx = |kx|\\ ky = |ky|\\ [kx, ky] = \mathsf{sort}([kx, ky])\\ \\ \sqrt{0.5 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, 2 \cdot \left(\frac{\ell}{Om} \cdot \sin ky\right)\right)}} \end{array} \]
NOTE: kx should be positive before calling this function
NOTE: ky should be positive before calling this function
NOTE: kx and ky should be sorted in increasing order before calling this function.
(FPCore (l Om kx ky)
 :precision binary64
 (sqrt (+ 0.5 (* 0.5 (/ 1.0 (hypot 1.0 (* 2.0 (* (/ l Om) (sin ky)))))))))
kx = abs(kx);
ky = abs(ky);
assert(kx < ky);
double code(double l, double Om, double kx, double ky) {
	return sqrt((0.5 + (0.5 * (1.0 / hypot(1.0, (2.0 * ((l / Om) * sin(ky))))))));
}
kx = Math.abs(kx);
ky = Math.abs(ky);
assert kx < ky;
public static double code(double l, double Om, double kx, double ky) {
	return Math.sqrt((0.5 + (0.5 * (1.0 / Math.hypot(1.0, (2.0 * ((l / Om) * Math.sin(ky))))))));
}
kx = abs(kx)
ky = abs(ky)
[kx, ky] = sort([kx, ky])
def code(l, Om, kx, ky):
	return math.sqrt((0.5 + (0.5 * (1.0 / math.hypot(1.0, (2.0 * ((l / Om) * math.sin(ky))))))))
kx = abs(kx)
ky = abs(ky)
kx, ky = sort([kx, ky])
function code(l, Om, kx, ky)
	return sqrt(Float64(0.5 + Float64(0.5 * Float64(1.0 / hypot(1.0, Float64(2.0 * Float64(Float64(l / Om) * sin(ky))))))))
end
kx = abs(kx)
ky = abs(ky)
kx, ky = num2cell(sort([kx, ky])){:}
function tmp = code(l, Om, kx, ky)
	tmp = sqrt((0.5 + (0.5 * (1.0 / hypot(1.0, (2.0 * ((l / Om) * sin(ky))))))));
end
NOTE: kx should be positive before calling this function
NOTE: ky should be positive before calling this function
NOTE: kx and ky should be sorted in increasing order before calling this function.
code[l_, Om_, kx_, ky_] := N[Sqrt[N[(0.5 + N[(0.5 * N[(1.0 / N[Sqrt[1.0 ^ 2 + N[(2.0 * N[(N[(l / Om), $MachinePrecision] * N[Sin[ky], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
kx = |kx|\\
ky = |ky|\\
[kx, ky] = \mathsf{sort}([kx, ky])\\
\\
\sqrt{0.5 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, 2 \cdot \left(\frac{\ell}{Om} \cdot \sin ky\right)\right)}}
\end{array}
Derivation
  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. Step-by-step derivation
    1. distribute-rgt-in98.4%

      \[\leadsto \sqrt{\color{blue}{1 \cdot \frac{1}{2} + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}}} \]
    2. metadata-eval98.4%

      \[\leadsto \sqrt{1 \cdot \color{blue}{0.5} + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}} \]
    3. metadata-eval98.4%

      \[\leadsto \sqrt{\color{blue}{0.5} + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}} \]
    4. associate-/l*98.4%

      \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + {\color{blue}{\left(\frac{2}{\frac{Om}{\ell}}\right)}}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}} \]
    5. metadata-eval98.4%

      \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + {\left(\frac{2}{\frac{Om}{\ell}}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \color{blue}{0.5}} \]
  3. Simplified98.4%

    \[\leadsto \color{blue}{\sqrt{0.5 + \frac{1}{\sqrt{1 + {\left(\frac{2}{\frac{Om}{\ell}}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot 0.5}} \]
  4. Taylor expanded in kx around 0 76.3%

    \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + \color{blue}{4 \cdot \frac{{\ell}^{2} \cdot {\sin ky}^{2}}{{Om}^{2}}}}} \cdot 0.5} \]
  5. Step-by-step derivation
    1. associate-/l*75.6%

      \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \color{blue}{\frac{{\ell}^{2}}{\frac{{Om}^{2}}{{\sin ky}^{2}}}}}} \cdot 0.5} \]
    2. associate-/r/76.6%

      \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \color{blue}{\left(\frac{{\ell}^{2}}{{Om}^{2}} \cdot {\sin ky}^{2}\right)}}} \cdot 0.5} \]
    3. unpow276.6%

      \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \left(\frac{\color{blue}{\ell \cdot \ell}}{{Om}^{2}} \cdot {\sin ky}^{2}\right)}} \cdot 0.5} \]
    4. unpow276.6%

      \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \left(\frac{\ell \cdot \ell}{\color{blue}{Om \cdot Om}} \cdot {\sin ky}^{2}\right)}} \cdot 0.5} \]
    5. times-frac89.0%

      \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \left(\color{blue}{\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right)} \cdot {\sin ky}^{2}\right)}} \cdot 0.5} \]
  6. Simplified89.0%

    \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + \color{blue}{4 \cdot \left(\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot {\sin ky}^{2}\right)}}} \cdot 0.5} \]
  7. Step-by-step derivation
    1. add-sqr-sqrt89.0%

      \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + \color{blue}{\sqrt{4 \cdot \left(\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot {\sin ky}^{2}\right)} \cdot \sqrt{4 \cdot \left(\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot {\sin ky}^{2}\right)}}}} \cdot 0.5} \]
    2. hypot-1-def89.0%

      \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{\mathsf{hypot}\left(1, \sqrt{4 \cdot \left(\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot {\sin ky}^{2}\right)}\right)}} \cdot 0.5} \]
    3. sqrt-prod89.0%

      \[\leadsto \sqrt{0.5 + \frac{1}{\mathsf{hypot}\left(1, \color{blue}{\sqrt{4} \cdot \sqrt{\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot {\sin ky}^{2}}}\right)} \cdot 0.5} \]
    4. metadata-eval89.0%

      \[\leadsto \sqrt{0.5 + \frac{1}{\mathsf{hypot}\left(1, \color{blue}{2} \cdot \sqrt{\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot {\sin ky}^{2}}\right)} \cdot 0.5} \]
    5. sqrt-prod89.0%

      \[\leadsto \sqrt{0.5 + \frac{1}{\mathsf{hypot}\left(1, 2 \cdot \color{blue}{\left(\sqrt{\frac{\ell}{Om} \cdot \frac{\ell}{Om}} \cdot \sqrt{{\sin ky}^{2}}\right)}\right)} \cdot 0.5} \]
    6. sqrt-prod48.1%

      \[\leadsto \sqrt{0.5 + \frac{1}{\mathsf{hypot}\left(1, 2 \cdot \left(\color{blue}{\left(\sqrt{\frac{\ell}{Om}} \cdot \sqrt{\frac{\ell}{Om}}\right)} \cdot \sqrt{{\sin ky}^{2}}\right)\right)} \cdot 0.5} \]
    7. add-sqr-sqrt89.7%

      \[\leadsto \sqrt{0.5 + \frac{1}{\mathsf{hypot}\left(1, 2 \cdot \left(\color{blue}{\frac{\ell}{Om}} \cdot \sqrt{{\sin ky}^{2}}\right)\right)} \cdot 0.5} \]
    8. unpow289.7%

      \[\leadsto \sqrt{0.5 + \frac{1}{\mathsf{hypot}\left(1, 2 \cdot \left(\frac{\ell}{Om} \cdot \sqrt{\color{blue}{\sin ky \cdot \sin ky}}\right)\right)} \cdot 0.5} \]
    9. sqrt-prod47.3%

      \[\leadsto \sqrt{0.5 + \frac{1}{\mathsf{hypot}\left(1, 2 \cdot \left(\frac{\ell}{Om} \cdot \color{blue}{\left(\sqrt{\sin ky} \cdot \sqrt{\sin ky}\right)}\right)\right)} \cdot 0.5} \]
    10. add-sqr-sqrt94.6%

      \[\leadsto \sqrt{0.5 + \frac{1}{\mathsf{hypot}\left(1, 2 \cdot \left(\frac{\ell}{Om} \cdot \color{blue}{\sin ky}\right)\right)} \cdot 0.5} \]
  8. Applied egg-rr94.6%

    \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{\mathsf{hypot}\left(1, 2 \cdot \left(\frac{\ell}{Om} \cdot \sin ky\right)\right)}} \cdot 0.5} \]
  9. Final simplification94.6%

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

Alternative 2: 72.2% accurate, 3.2× speedup?

\[\begin{array}{l} kx = |kx|\\ ky = |ky|\\ [kx, ky] = \mathsf{sort}([kx, ky])\\ \\ \begin{array}{l} \mathbf{if}\;Om \leq 4.8 \cdot 10^{-154}:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{elif}\;Om \leq 3.6 \cdot 10^{+149}:\\ \;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{1}{1 + 2 \cdot \frac{0.5 + \cos \left(2 \cdot ky\right) \cdot -0.5}{\frac{Om \cdot Om}{\ell \cdot \ell}}}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
NOTE: kx should be positive before calling this function
NOTE: ky should be positive before calling this function
NOTE: kx and ky should be sorted in increasing order before calling this function.
(FPCore (l Om kx ky)
 :precision binary64
 (if (<= Om 4.8e-154)
   (sqrt 0.5)
   (if (<= Om 3.6e+149)
     (sqrt
      (+
       0.5
       (*
        0.5
        (/
         1.0
         (+
          1.0
          (*
           2.0
           (/ (+ 0.5 (* (cos (* 2.0 ky)) -0.5)) (/ (* Om Om) (* l l)))))))))
     1.0)))
kx = abs(kx);
ky = abs(ky);
assert(kx < ky);
double code(double l, double Om, double kx, double ky) {
	double tmp;
	if (Om <= 4.8e-154) {
		tmp = sqrt(0.5);
	} else if (Om <= 3.6e+149) {
		tmp = sqrt((0.5 + (0.5 * (1.0 / (1.0 + (2.0 * ((0.5 + (cos((2.0 * ky)) * -0.5)) / ((Om * Om) / (l * l)))))))));
	} else {
		tmp = 1.0;
	}
	return tmp;
}
NOTE: kx should be positive before calling this function
NOTE: ky should be positive before calling this function
NOTE: kx and ky should be sorted in increasing order before calling this function.
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
    real(8) :: tmp
    if (om <= 4.8d-154) then
        tmp = sqrt(0.5d0)
    else if (om <= 3.6d+149) then
        tmp = sqrt((0.5d0 + (0.5d0 * (1.0d0 / (1.0d0 + (2.0d0 * ((0.5d0 + (cos((2.0d0 * ky)) * (-0.5d0))) / ((om * om) / (l * l)))))))))
    else
        tmp = 1.0d0
    end if
    code = tmp
end function
kx = Math.abs(kx);
ky = Math.abs(ky);
assert kx < ky;
public static double code(double l, double Om, double kx, double ky) {
	double tmp;
	if (Om <= 4.8e-154) {
		tmp = Math.sqrt(0.5);
	} else if (Om <= 3.6e+149) {
		tmp = Math.sqrt((0.5 + (0.5 * (1.0 / (1.0 + (2.0 * ((0.5 + (Math.cos((2.0 * ky)) * -0.5)) / ((Om * Om) / (l * l)))))))));
	} else {
		tmp = 1.0;
	}
	return tmp;
}
kx = abs(kx)
ky = abs(ky)
[kx, ky] = sort([kx, ky])
def code(l, Om, kx, ky):
	tmp = 0
	if Om <= 4.8e-154:
		tmp = math.sqrt(0.5)
	elif Om <= 3.6e+149:
		tmp = math.sqrt((0.5 + (0.5 * (1.0 / (1.0 + (2.0 * ((0.5 + (math.cos((2.0 * ky)) * -0.5)) / ((Om * Om) / (l * l)))))))))
	else:
		tmp = 1.0
	return tmp
kx = abs(kx)
ky = abs(ky)
kx, ky = sort([kx, ky])
function code(l, Om, kx, ky)
	tmp = 0.0
	if (Om <= 4.8e-154)
		tmp = sqrt(0.5);
	elseif (Om <= 3.6e+149)
		tmp = sqrt(Float64(0.5 + Float64(0.5 * Float64(1.0 / Float64(1.0 + Float64(2.0 * Float64(Float64(0.5 + Float64(cos(Float64(2.0 * ky)) * -0.5)) / Float64(Float64(Om * Om) / Float64(l * l)))))))));
	else
		tmp = 1.0;
	end
	return tmp
end
kx = abs(kx)
ky = abs(ky)
kx, ky = num2cell(sort([kx, ky])){:}
function tmp_2 = code(l, Om, kx, ky)
	tmp = 0.0;
	if (Om <= 4.8e-154)
		tmp = sqrt(0.5);
	elseif (Om <= 3.6e+149)
		tmp = sqrt((0.5 + (0.5 * (1.0 / (1.0 + (2.0 * ((0.5 + (cos((2.0 * ky)) * -0.5)) / ((Om * Om) / (l * l)))))))));
	else
		tmp = 1.0;
	end
	tmp_2 = tmp;
end
NOTE: kx should be positive before calling this function
NOTE: ky should be positive before calling this function
NOTE: kx and ky should be sorted in increasing order before calling this function.
code[l_, Om_, kx_, ky_] := If[LessEqual[Om, 4.8e-154], N[Sqrt[0.5], $MachinePrecision], If[LessEqual[Om, 3.6e+149], N[Sqrt[N[(0.5 + N[(0.5 * N[(1.0 / N[(1.0 + N[(2.0 * N[(N[(0.5 + N[(N[Cos[N[(2.0 * ky), $MachinePrecision]], $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision] / N[(N[(Om * Om), $MachinePrecision] / N[(l * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 1.0]]
\begin{array}{l}
kx = |kx|\\
ky = |ky|\\
[kx, ky] = \mathsf{sort}([kx, ky])\\
\\
\begin{array}{l}
\mathbf{if}\;Om \leq 4.8 \cdot 10^{-154}:\\
\;\;\;\;\sqrt{0.5}\\

\mathbf{elif}\;Om \leq 3.6 \cdot 10^{+149}:\\
\;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{1}{1 + 2 \cdot \frac{0.5 + \cos \left(2 \cdot ky\right) \cdot -0.5}{\frac{Om \cdot Om}{\ell \cdot \ell}}}}\\

\mathbf{else}:\\
\;\;\;\;1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if Om < 4.79999999999999974e-154

    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. Step-by-step derivation
      1. distribute-rgt-in98.1%

        \[\leadsto \sqrt{\color{blue}{1 \cdot \frac{1}{2} + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}}} \]
      2. metadata-eval98.1%

        \[\leadsto \sqrt{1 \cdot \color{blue}{0.5} + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}} \]
      3. metadata-eval98.1%

        \[\leadsto \sqrt{\color{blue}{0.5} + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}} \]
      4. associate-/l*98.1%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + {\color{blue}{\left(\frac{2}{\frac{Om}{\ell}}\right)}}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}} \]
      5. metadata-eval98.1%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + {\left(\frac{2}{\frac{Om}{\ell}}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \color{blue}{0.5}} \]
    3. Simplified98.1%

      \[\leadsto \color{blue}{\sqrt{0.5 + \frac{1}{\sqrt{1 + {\left(\frac{2}{\frac{Om}{\ell}}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot 0.5}} \]
    4. Taylor expanded in Om around 0 51.3%

      \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{2 \cdot \left(\sqrt{{\sin ky}^{2} + {\sin kx}^{2}} \cdot \frac{\ell}{Om}\right)}} \cdot 0.5} \]
    5. Step-by-step derivation
      1. associate-*r*51.3%

        \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{\left(2 \cdot \sqrt{{\sin ky}^{2} + {\sin kx}^{2}}\right) \cdot \frac{\ell}{Om}}} \cdot 0.5} \]
      2. *-commutative51.3%

        \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{\left(\sqrt{{\sin ky}^{2} + {\sin kx}^{2}} \cdot 2\right)} \cdot \frac{\ell}{Om}} \cdot 0.5} \]
      3. associate-*r*51.3%

        \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{\sqrt{{\sin ky}^{2} + {\sin kx}^{2}} \cdot \left(2 \cdot \frac{\ell}{Om}\right)}} \cdot 0.5} \]
      4. unpow251.3%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}} \cdot \left(2 \cdot \frac{\ell}{Om}\right)} \cdot 0.5} \]
      5. unpow251.3%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}} \cdot \left(2 \cdot \frac{\ell}{Om}\right)} \cdot 0.5} \]
      6. hypot-def53.3%

        \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(2 \cdot \frac{\ell}{Om}\right)} \cdot 0.5} \]
    6. Simplified53.3%

      \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right) \cdot \left(2 \cdot \frac{\ell}{Om}\right)}} \cdot 0.5} \]
    7. Taylor expanded in l around inf 60.8%

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

    if 4.79999999999999974e-154 < Om < 3.59999999999999995e149

    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. Step-by-step derivation
      1. distribute-rgt-in98.6%

        \[\leadsto \sqrt{\color{blue}{1 \cdot \frac{1}{2} + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}}} \]
      2. metadata-eval98.6%

        \[\leadsto \sqrt{1 \cdot \color{blue}{0.5} + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}} \]
      3. metadata-eval98.6%

        \[\leadsto \sqrt{\color{blue}{0.5} + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}} \]
      4. associate-/l*98.6%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + {\color{blue}{\left(\frac{2}{\frac{Om}{\ell}}\right)}}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}} \]
      5. metadata-eval98.6%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + {\left(\frac{2}{\frac{Om}{\ell}}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \color{blue}{0.5}} \]
    3. Simplified98.6%

      \[\leadsto \color{blue}{\sqrt{0.5 + \frac{1}{\sqrt{1 + {\left(\frac{2}{\frac{Om}{\ell}}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot 0.5}} \]
    4. Taylor expanded in kx around 0 92.9%

      \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + \color{blue}{4 \cdot \frac{{\ell}^{2} \cdot {\sin ky}^{2}}{{Om}^{2}}}}} \cdot 0.5} \]
    5. Step-by-step derivation
      1. associate-/l*90.0%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \color{blue}{\frac{{\ell}^{2}}{\frac{{Om}^{2}}{{\sin ky}^{2}}}}}} \cdot 0.5} \]
      2. associate-/r/92.9%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \color{blue}{\left(\frac{{\ell}^{2}}{{Om}^{2}} \cdot {\sin ky}^{2}\right)}}} \cdot 0.5} \]
      3. unpow292.9%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \left(\frac{\color{blue}{\ell \cdot \ell}}{{Om}^{2}} \cdot {\sin ky}^{2}\right)}} \cdot 0.5} \]
      4. unpow292.9%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \left(\frac{\ell \cdot \ell}{\color{blue}{Om \cdot Om}} \cdot {\sin ky}^{2}\right)}} \cdot 0.5} \]
      5. times-frac92.0%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \left(\color{blue}{\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right)} \cdot {\sin ky}^{2}\right)}} \cdot 0.5} \]
    6. Simplified92.0%

      \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + \color{blue}{4 \cdot \left(\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot {\sin ky}^{2}\right)}}} \cdot 0.5} \]
    7. Step-by-step derivation
      1. unpow292.0%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \left(\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot \color{blue}{\left(\sin ky \cdot \sin ky\right)}\right)}} \cdot 0.5} \]
      2. sin-mult82.2%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \left(\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot \color{blue}{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2}}\right)}} \cdot 0.5} \]
      3. cos-sum82.2%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \left(\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot \frac{\cos \left(ky - ky\right) - \color{blue}{\left(\cos ky \cdot \cos ky - \sin ky \cdot \sin ky\right)}}{2}\right)}} \cdot 0.5} \]
      4. cos-282.2%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \left(\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot \frac{\cos \left(ky - ky\right) - \color{blue}{\cos \left(2 \cdot ky\right)}}{2}\right)}} \cdot 0.5} \]
    8. Applied egg-rr82.2%

      \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \left(\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot \color{blue}{\frac{\cos \left(ky - ky\right) - \cos \left(2 \cdot ky\right)}{2}}\right)}} \cdot 0.5} \]
    9. Step-by-step derivation
      1. div-sub82.2%

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

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

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \left(\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot \left(\frac{\color{blue}{1}}{2} - \frac{\cos \left(2 \cdot ky\right)}{2}\right)\right)}} \cdot 0.5} \]
      4. metadata-eval82.2%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \left(\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot \left(\color{blue}{0.5} - \frac{\cos \left(2 \cdot ky\right)}{2}\right)\right)}} \cdot 0.5} \]
    10. Simplified82.2%

      \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \left(\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot \color{blue}{\left(0.5 - \frac{\cos \left(2 \cdot ky\right)}{2}\right)}\right)}} \cdot 0.5} \]
    11. Taylor expanded in l around 0 81.8%

      \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{1 + 2 \cdot \frac{\left(0.5 - 0.5 \cdot \cos \left(2 \cdot ky\right)\right) \cdot {\ell}^{2}}{{Om}^{2}}}} \cdot 0.5} \]
    12. Step-by-step derivation
      1. associate-/l*81.8%

        \[\leadsto \sqrt{0.5 + \frac{1}{1 + 2 \cdot \color{blue}{\frac{0.5 - 0.5 \cdot \cos \left(2 \cdot ky\right)}{\frac{{Om}^{2}}{{\ell}^{2}}}}} \cdot 0.5} \]
      2. sub-neg81.8%

        \[\leadsto \sqrt{0.5 + \frac{1}{1 + 2 \cdot \frac{\color{blue}{0.5 + \left(-0.5 \cdot \cos \left(2 \cdot ky\right)\right)}}{\frac{{Om}^{2}}{{\ell}^{2}}}} \cdot 0.5} \]
      3. *-commutative81.8%

        \[\leadsto \sqrt{0.5 + \frac{1}{1 + 2 \cdot \frac{0.5 + \left(-\color{blue}{\cos \left(2 \cdot ky\right) \cdot 0.5}\right)}{\frac{{Om}^{2}}{{\ell}^{2}}}} \cdot 0.5} \]
      4. distribute-rgt-neg-in81.8%

        \[\leadsto \sqrt{0.5 + \frac{1}{1 + 2 \cdot \frac{0.5 + \color{blue}{\cos \left(2 \cdot ky\right) \cdot \left(-0.5\right)}}{\frac{{Om}^{2}}{{\ell}^{2}}}} \cdot 0.5} \]
      5. metadata-eval81.8%

        \[\leadsto \sqrt{0.5 + \frac{1}{1 + 2 \cdot \frac{0.5 + \cos \left(2 \cdot ky\right) \cdot \color{blue}{-0.5}}{\frac{{Om}^{2}}{{\ell}^{2}}}} \cdot 0.5} \]
      6. unpow281.8%

        \[\leadsto \sqrt{0.5 + \frac{1}{1 + 2 \cdot \frac{0.5 + \cos \left(2 \cdot ky\right) \cdot -0.5}{\frac{\color{blue}{Om \cdot Om}}{{\ell}^{2}}}} \cdot 0.5} \]
      7. unpow281.8%

        \[\leadsto \sqrt{0.5 + \frac{1}{1 + 2 \cdot \frac{0.5 + \cos \left(2 \cdot ky\right) \cdot -0.5}{\frac{Om \cdot Om}{\color{blue}{\ell \cdot \ell}}}} \cdot 0.5} \]
    13. Simplified81.8%

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

    if 3.59999999999999995e149 < Om

    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. Step-by-step derivation
      1. distribute-rgt-in100.0%

        \[\leadsto \sqrt{\color{blue}{1 \cdot \frac{1}{2} + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}}} \]
      2. metadata-eval100.0%

        \[\leadsto \sqrt{1 \cdot \color{blue}{0.5} + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}} \]
      3. metadata-eval100.0%

        \[\leadsto \sqrt{\color{blue}{0.5} + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}} \]
      4. associate-/l*100.0%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + {\color{blue}{\left(\frac{2}{\frac{Om}{\ell}}\right)}}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}} \]
      5. metadata-eval100.0%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + {\left(\frac{2}{\frac{Om}{\ell}}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \color{blue}{0.5}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\sqrt{0.5 + \frac{1}{\sqrt{1 + {\left(\frac{2}{\frac{Om}{\ell}}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot 0.5}} \]
    4. Taylor expanded in kx around 0 69.7%

      \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + \color{blue}{4 \cdot \frac{{\ell}^{2} \cdot {\sin ky}^{2}}{{Om}^{2}}}}} \cdot 0.5} \]
    5. Step-by-step derivation
      1. associate-/l*69.7%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \color{blue}{\frac{{\ell}^{2}}{\frac{{Om}^{2}}{{\sin ky}^{2}}}}}} \cdot 0.5} \]
      2. associate-/r/69.7%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \color{blue}{\left(\frac{{\ell}^{2}}{{Om}^{2}} \cdot {\sin ky}^{2}\right)}}} \cdot 0.5} \]
      3. unpow269.7%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \left(\frac{\color{blue}{\ell \cdot \ell}}{{Om}^{2}} \cdot {\sin ky}^{2}\right)}} \cdot 0.5} \]
      4. unpow269.7%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \left(\frac{\ell \cdot \ell}{\color{blue}{Om \cdot Om}} \cdot {\sin ky}^{2}\right)}} \cdot 0.5} \]
      5. times-frac97.6%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \left(\color{blue}{\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right)} \cdot {\sin ky}^{2}\right)}} \cdot 0.5} \]
    6. Simplified97.6%

      \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + \color{blue}{4 \cdot \left(\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot {\sin ky}^{2}\right)}}} \cdot 0.5} \]
    7. Step-by-step derivation
      1. add-sqr-sqrt97.6%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + \color{blue}{\sqrt{4 \cdot \left(\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot {\sin ky}^{2}\right)} \cdot \sqrt{4 \cdot \left(\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot {\sin ky}^{2}\right)}}}} \cdot 0.5} \]
      2. hypot-1-def97.6%

        \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{\mathsf{hypot}\left(1, \sqrt{4 \cdot \left(\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot {\sin ky}^{2}\right)}\right)}} \cdot 0.5} \]
      3. sqrt-prod97.6%

        \[\leadsto \sqrt{0.5 + \frac{1}{\mathsf{hypot}\left(1, \color{blue}{\sqrt{4} \cdot \sqrt{\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot {\sin ky}^{2}}}\right)} \cdot 0.5} \]
      4. metadata-eval97.6%

        \[\leadsto \sqrt{0.5 + \frac{1}{\mathsf{hypot}\left(1, \color{blue}{2} \cdot \sqrt{\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot {\sin ky}^{2}}\right)} \cdot 0.5} \]
      5. sqrt-prod97.6%

        \[\leadsto \sqrt{0.5 + \frac{1}{\mathsf{hypot}\left(1, 2 \cdot \color{blue}{\left(\sqrt{\frac{\ell}{Om} \cdot \frac{\ell}{Om}} \cdot \sqrt{{\sin ky}^{2}}\right)}\right)} \cdot 0.5} \]
      6. sqrt-prod58.2%

        \[\leadsto \sqrt{0.5 + \frac{1}{\mathsf{hypot}\left(1, 2 \cdot \left(\color{blue}{\left(\sqrt{\frac{\ell}{Om}} \cdot \sqrt{\frac{\ell}{Om}}\right)} \cdot \sqrt{{\sin ky}^{2}}\right)\right)} \cdot 0.5} \]
      7. add-sqr-sqrt97.6%

        \[\leadsto \sqrt{0.5 + \frac{1}{\mathsf{hypot}\left(1, 2 \cdot \left(\color{blue}{\frac{\ell}{Om}} \cdot \sqrt{{\sin ky}^{2}}\right)\right)} \cdot 0.5} \]
      8. unpow297.6%

        \[\leadsto \sqrt{0.5 + \frac{1}{\mathsf{hypot}\left(1, 2 \cdot \left(\frac{\ell}{Om} \cdot \sqrt{\color{blue}{\sin ky \cdot \sin ky}}\right)\right)} \cdot 0.5} \]
      9. sqrt-prod57.6%

        \[\leadsto \sqrt{0.5 + \frac{1}{\mathsf{hypot}\left(1, 2 \cdot \left(\frac{\ell}{Om} \cdot \color{blue}{\left(\sqrt{\sin ky} \cdot \sqrt{\sin ky}\right)}\right)\right)} \cdot 0.5} \]
      10. add-sqr-sqrt97.6%

        \[\leadsto \sqrt{0.5 + \frac{1}{\mathsf{hypot}\left(1, 2 \cdot \left(\frac{\ell}{Om} \cdot \color{blue}{\sin ky}\right)\right)} \cdot 0.5} \]
    8. Applied egg-rr97.6%

      \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{\mathsf{hypot}\left(1, 2 \cdot \left(\frac{\ell}{Om} \cdot \sin ky\right)\right)}} \cdot 0.5} \]
    9. Taylor expanded in l around 0 90.3%

      \[\leadsto \sqrt{0.5 + \color{blue}{1} \cdot 0.5} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification70.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;Om \leq 4.8 \cdot 10^{-154}:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{elif}\;Om \leq 3.6 \cdot 10^{+149}:\\ \;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{1}{1 + 2 \cdot \frac{0.5 + \cos \left(2 \cdot ky\right) \cdot -0.5}{\frac{Om \cdot Om}{\ell \cdot \ell}}}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]

Alternative 3: 69.7% accurate, 6.4× speedup?

\[\begin{array}{l} kx = |kx|\\ ky = |ky|\\ [kx, ky] = \mathsf{sort}([kx, ky])\\ \\ \begin{array}{l} \mathbf{if}\;\ell \leq 9.5 \cdot 10^{-31}:\\ \;\;\;\;1\\ \mathbf{elif}\;\ell \leq 28000000:\\ \;\;\;\;\sqrt{0.5 + 0.25 \cdot \frac{Om}{\ell \cdot ky}}\\ \mathbf{elif}\;\ell \leq 9.8 \cdot 10^{+119}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \end{array} \]
NOTE: kx should be positive before calling this function
NOTE: ky should be positive before calling this function
NOTE: kx and ky should be sorted in increasing order before calling this function.
(FPCore (l Om kx ky)
 :precision binary64
 (if (<= l 9.5e-31)
   1.0
   (if (<= l 28000000.0)
     (sqrt (+ 0.5 (* 0.25 (/ Om (* l ky)))))
     (if (<= l 9.8e+119) 1.0 (sqrt 0.5)))))
kx = abs(kx);
ky = abs(ky);
assert(kx < ky);
double code(double l, double Om, double kx, double ky) {
	double tmp;
	if (l <= 9.5e-31) {
		tmp = 1.0;
	} else if (l <= 28000000.0) {
		tmp = sqrt((0.5 + (0.25 * (Om / (l * ky)))));
	} else if (l <= 9.8e+119) {
		tmp = 1.0;
	} else {
		tmp = sqrt(0.5);
	}
	return tmp;
}
NOTE: kx should be positive before calling this function
NOTE: ky should be positive before calling this function
NOTE: kx and ky should be sorted in increasing order before calling this function.
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
    real(8) :: tmp
    if (l <= 9.5d-31) then
        tmp = 1.0d0
    else if (l <= 28000000.0d0) then
        tmp = sqrt((0.5d0 + (0.25d0 * (om / (l * ky)))))
    else if (l <= 9.8d+119) then
        tmp = 1.0d0
    else
        tmp = sqrt(0.5d0)
    end if
    code = tmp
end function
kx = Math.abs(kx);
ky = Math.abs(ky);
assert kx < ky;
public static double code(double l, double Om, double kx, double ky) {
	double tmp;
	if (l <= 9.5e-31) {
		tmp = 1.0;
	} else if (l <= 28000000.0) {
		tmp = Math.sqrt((0.5 + (0.25 * (Om / (l * ky)))));
	} else if (l <= 9.8e+119) {
		tmp = 1.0;
	} else {
		tmp = Math.sqrt(0.5);
	}
	return tmp;
}
kx = abs(kx)
ky = abs(ky)
[kx, ky] = sort([kx, ky])
def code(l, Om, kx, ky):
	tmp = 0
	if l <= 9.5e-31:
		tmp = 1.0
	elif l <= 28000000.0:
		tmp = math.sqrt((0.5 + (0.25 * (Om / (l * ky)))))
	elif l <= 9.8e+119:
		tmp = 1.0
	else:
		tmp = math.sqrt(0.5)
	return tmp
kx = abs(kx)
ky = abs(ky)
kx, ky = sort([kx, ky])
function code(l, Om, kx, ky)
	tmp = 0.0
	if (l <= 9.5e-31)
		tmp = 1.0;
	elseif (l <= 28000000.0)
		tmp = sqrt(Float64(0.5 + Float64(0.25 * Float64(Om / Float64(l * ky)))));
	elseif (l <= 9.8e+119)
		tmp = 1.0;
	else
		tmp = sqrt(0.5);
	end
	return tmp
end
kx = abs(kx)
ky = abs(ky)
kx, ky = num2cell(sort([kx, ky])){:}
function tmp_2 = code(l, Om, kx, ky)
	tmp = 0.0;
	if (l <= 9.5e-31)
		tmp = 1.0;
	elseif (l <= 28000000.0)
		tmp = sqrt((0.5 + (0.25 * (Om / (l * ky)))));
	elseif (l <= 9.8e+119)
		tmp = 1.0;
	else
		tmp = sqrt(0.5);
	end
	tmp_2 = tmp;
end
NOTE: kx should be positive before calling this function
NOTE: ky should be positive before calling this function
NOTE: kx and ky should be sorted in increasing order before calling this function.
code[l_, Om_, kx_, ky_] := If[LessEqual[l, 9.5e-31], 1.0, If[LessEqual[l, 28000000.0], N[Sqrt[N[(0.5 + N[(0.25 * N[(Om / N[(l * ky), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[l, 9.8e+119], 1.0, N[Sqrt[0.5], $MachinePrecision]]]]
\begin{array}{l}
kx = |kx|\\
ky = |ky|\\
[kx, ky] = \mathsf{sort}([kx, ky])\\
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 9.5 \cdot 10^{-31}:\\
\;\;\;\;1\\

\mathbf{elif}\;\ell \leq 28000000:\\
\;\;\;\;\sqrt{0.5 + 0.25 \cdot \frac{Om}{\ell \cdot ky}}\\

\mathbf{elif}\;\ell \leq 9.8 \cdot 10^{+119}:\\
\;\;\;\;1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < 9.5000000000000008e-31 or 2.8e7 < l < 9.79999999999999992e119

    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. Step-by-step derivation
      1. distribute-rgt-in98.1%

        \[\leadsto \sqrt{\color{blue}{1 \cdot \frac{1}{2} + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}}} \]
      2. metadata-eval98.1%

        \[\leadsto \sqrt{1 \cdot \color{blue}{0.5} + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}} \]
      3. metadata-eval98.1%

        \[\leadsto \sqrt{\color{blue}{0.5} + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}} \]
      4. associate-/l*98.1%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + {\color{blue}{\left(\frac{2}{\frac{Om}{\ell}}\right)}}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}} \]
      5. metadata-eval98.1%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + {\left(\frac{2}{\frac{Om}{\ell}}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \color{blue}{0.5}} \]
    3. Simplified98.1%

      \[\leadsto \color{blue}{\sqrt{0.5 + \frac{1}{\sqrt{1 + {\left(\frac{2}{\frac{Om}{\ell}}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot 0.5}} \]
    4. Taylor expanded in kx around 0 77.9%

      \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + \color{blue}{4 \cdot \frac{{\ell}^{2} \cdot {\sin ky}^{2}}{{Om}^{2}}}}} \cdot 0.5} \]
    5. Step-by-step derivation
      1. associate-/l*78.4%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \color{blue}{\frac{{\ell}^{2}}{\frac{{Om}^{2}}{{\sin ky}^{2}}}}}} \cdot 0.5} \]
      2. associate-/r/78.3%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \color{blue}{\left(\frac{{\ell}^{2}}{{Om}^{2}} \cdot {\sin ky}^{2}\right)}}} \cdot 0.5} \]
      3. unpow278.3%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \left(\frac{\color{blue}{\ell \cdot \ell}}{{Om}^{2}} \cdot {\sin ky}^{2}\right)}} \cdot 0.5} \]
      4. unpow278.3%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \left(\frac{\ell \cdot \ell}{\color{blue}{Om \cdot Om}} \cdot {\sin ky}^{2}\right)}} \cdot 0.5} \]
      5. times-frac90.1%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \left(\color{blue}{\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right)} \cdot {\sin ky}^{2}\right)}} \cdot 0.5} \]
    6. Simplified90.1%

      \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + \color{blue}{4 \cdot \left(\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot {\sin ky}^{2}\right)}}} \cdot 0.5} \]
    7. Step-by-step derivation
      1. add-sqr-sqrt90.1%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + \color{blue}{\sqrt{4 \cdot \left(\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot {\sin ky}^{2}\right)} \cdot \sqrt{4 \cdot \left(\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot {\sin ky}^{2}\right)}}}} \cdot 0.5} \]
      2. hypot-1-def90.1%

        \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{\mathsf{hypot}\left(1, \sqrt{4 \cdot \left(\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot {\sin ky}^{2}\right)}\right)}} \cdot 0.5} \]
      3. sqrt-prod90.1%

        \[\leadsto \sqrt{0.5 + \frac{1}{\mathsf{hypot}\left(1, \color{blue}{\sqrt{4} \cdot \sqrt{\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot {\sin ky}^{2}}}\right)} \cdot 0.5} \]
      4. metadata-eval90.1%

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

        \[\leadsto \sqrt{0.5 + \frac{1}{\mathsf{hypot}\left(1, 2 \cdot \color{blue}{\left(\sqrt{\frac{\ell}{Om} \cdot \frac{\ell}{Om}} \cdot \sqrt{{\sin ky}^{2}}\right)}\right)} \cdot 0.5} \]
      6. sqrt-prod50.6%

        \[\leadsto \sqrt{0.5 + \frac{1}{\mathsf{hypot}\left(1, 2 \cdot \left(\color{blue}{\left(\sqrt{\frac{\ell}{Om}} \cdot \sqrt{\frac{\ell}{Om}}\right)} \cdot \sqrt{{\sin ky}^{2}}\right)\right)} \cdot 0.5} \]
      7. add-sqr-sqrt90.7%

        \[\leadsto \sqrt{0.5 + \frac{1}{\mathsf{hypot}\left(1, 2 \cdot \left(\color{blue}{\frac{\ell}{Om}} \cdot \sqrt{{\sin ky}^{2}}\right)\right)} \cdot 0.5} \]
      8. unpow290.7%

        \[\leadsto \sqrt{0.5 + \frac{1}{\mathsf{hypot}\left(1, 2 \cdot \left(\frac{\ell}{Om} \cdot \sqrt{\color{blue}{\sin ky \cdot \sin ky}}\right)\right)} \cdot 0.5} \]
      9. sqrt-prod46.1%

        \[\leadsto \sqrt{0.5 + \frac{1}{\mathsf{hypot}\left(1, 2 \cdot \left(\frac{\ell}{Om} \cdot \color{blue}{\left(\sqrt{\sin ky} \cdot \sqrt{\sin ky}\right)}\right)\right)} \cdot 0.5} \]
      10. add-sqr-sqrt95.1%

        \[\leadsto \sqrt{0.5 + \frac{1}{\mathsf{hypot}\left(1, 2 \cdot \left(\frac{\ell}{Om} \cdot \color{blue}{\sin ky}\right)\right)} \cdot 0.5} \]
    8. Applied egg-rr95.1%

      \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{\mathsf{hypot}\left(1, 2 \cdot \left(\frac{\ell}{Om} \cdot \sin ky\right)\right)}} \cdot 0.5} \]
    9. Taylor expanded in l around 0 70.8%

      \[\leadsto \sqrt{0.5 + \color{blue}{1} \cdot 0.5} \]

    if 9.5000000000000008e-31 < l < 2.8e7

    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. Step-by-step derivation
      1. distribute-rgt-in100.0%

        \[\leadsto \sqrt{\color{blue}{1 \cdot \frac{1}{2} + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}}} \]
      2. metadata-eval100.0%

        \[\leadsto \sqrt{1 \cdot \color{blue}{0.5} + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}} \]
      3. metadata-eval100.0%

        \[\leadsto \sqrt{\color{blue}{0.5} + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}} \]
      4. associate-/l*100.0%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + {\color{blue}{\left(\frac{2}{\frac{Om}{\ell}}\right)}}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}} \]
      5. metadata-eval100.0%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + {\left(\frac{2}{\frac{Om}{\ell}}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \color{blue}{0.5}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\sqrt{0.5 + \frac{1}{\sqrt{1 + {\left(\frac{2}{\frac{Om}{\ell}}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot 0.5}} \]
    4. Taylor expanded in Om around 0 100.0%

      \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{2 \cdot \left(\sqrt{{\sin ky}^{2} + {\sin kx}^{2}} \cdot \frac{\ell}{Om}\right)}} \cdot 0.5} \]
    5. Step-by-step derivation
      1. associate-*r*100.0%

        \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{\left(2 \cdot \sqrt{{\sin ky}^{2} + {\sin kx}^{2}}\right) \cdot \frac{\ell}{Om}}} \cdot 0.5} \]
      2. *-commutative100.0%

        \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{\left(\sqrt{{\sin ky}^{2} + {\sin kx}^{2}} \cdot 2\right)} \cdot \frac{\ell}{Om}} \cdot 0.5} \]
      3. associate-*r*100.0%

        \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{\sqrt{{\sin ky}^{2} + {\sin kx}^{2}} \cdot \left(2 \cdot \frac{\ell}{Om}\right)}} \cdot 0.5} \]
      4. unpow2100.0%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}} \cdot \left(2 \cdot \frac{\ell}{Om}\right)} \cdot 0.5} \]
      5. unpow2100.0%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}} \cdot \left(2 \cdot \frac{\ell}{Om}\right)} \cdot 0.5} \]
      6. hypot-def100.0%

        \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(2 \cdot \frac{\ell}{Om}\right)} \cdot 0.5} \]
    6. Simplified100.0%

      \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right) \cdot \left(2 \cdot \frac{\ell}{Om}\right)}} \cdot 0.5} \]
    7. Taylor expanded in kx around 0 98.4%

      \[\leadsto \color{blue}{\sqrt{0.5 + 0.25 \cdot \frac{Om}{\ell \cdot \sin ky}}} \]
    8. Step-by-step derivation
      1. +-commutative98.4%

        \[\leadsto \sqrt{\color{blue}{0.25 \cdot \frac{Om}{\ell \cdot \sin ky} + 0.5}} \]
    9. Simplified98.4%

      \[\leadsto \color{blue}{\sqrt{0.25 \cdot \frac{Om}{\ell \cdot \sin ky} + 0.5}} \]
    10. Taylor expanded in ky around 0 98.4%

      \[\leadsto \sqrt{0.25 \cdot \frac{Om}{\color{blue}{\ell \cdot ky}} + 0.5} \]

    if 9.79999999999999992e119 < l

    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. Step-by-step derivation
      1. distribute-rgt-in100.0%

        \[\leadsto \sqrt{\color{blue}{1 \cdot \frac{1}{2} + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}}} \]
      2. metadata-eval100.0%

        \[\leadsto \sqrt{1 \cdot \color{blue}{0.5} + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}} \]
      3. metadata-eval100.0%

        \[\leadsto \sqrt{\color{blue}{0.5} + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}} \]
      4. associate-/l*100.0%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + {\color{blue}{\left(\frac{2}{\frac{Om}{\ell}}\right)}}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}} \]
      5. metadata-eval100.0%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + {\left(\frac{2}{\frac{Om}{\ell}}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \color{blue}{0.5}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\sqrt{0.5 + \frac{1}{\sqrt{1 + {\left(\frac{2}{\frac{Om}{\ell}}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot 0.5}} \]
    4. Taylor expanded in Om around 0 81.9%

      \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{2 \cdot \left(\sqrt{{\sin ky}^{2} + {\sin kx}^{2}} \cdot \frac{\ell}{Om}\right)}} \cdot 0.5} \]
    5. Step-by-step derivation
      1. associate-*r*81.9%

        \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{\left(2 \cdot \sqrt{{\sin ky}^{2} + {\sin kx}^{2}}\right) \cdot \frac{\ell}{Om}}} \cdot 0.5} \]
      2. *-commutative81.9%

        \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{\left(\sqrt{{\sin ky}^{2} + {\sin kx}^{2}} \cdot 2\right)} \cdot \frac{\ell}{Om}} \cdot 0.5} \]
      3. associate-*r*81.9%

        \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{\sqrt{{\sin ky}^{2} + {\sin kx}^{2}} \cdot \left(2 \cdot \frac{\ell}{Om}\right)}} \cdot 0.5} \]
      4. unpow281.9%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}} \cdot \left(2 \cdot \frac{\ell}{Om}\right)} \cdot 0.5} \]
      5. unpow281.9%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}} \cdot \left(2 \cdot \frac{\ell}{Om}\right)} \cdot 0.5} \]
      6. hypot-def81.9%

        \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(2 \cdot \frac{\ell}{Om}\right)} \cdot 0.5} \]
    6. Simplified81.9%

      \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right) \cdot \left(2 \cdot \frac{\ell}{Om}\right)}} \cdot 0.5} \]
    7. Taylor expanded in l around inf 84.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 9.5 \cdot 10^{-31}:\\ \;\;\;\;1\\ \mathbf{elif}\;\ell \leq 28000000:\\ \;\;\;\;\sqrt{0.5 + 0.25 \cdot \frac{Om}{\ell \cdot ky}}\\ \mathbf{elif}\;\ell \leq 9.8 \cdot 10^{+119}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \]

Alternative 4: 69.9% accurate, 6.7× speedup?

\[\begin{array}{l} kx = |kx|\\ ky = |ky|\\ [kx, ky] = \mathsf{sort}([kx, ky])\\ \\ \begin{array}{l} \mathbf{if}\;\ell \leq 9 \cdot 10^{-31}:\\ \;\;\;\;1\\ \mathbf{elif}\;\ell \leq 50000000:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{elif}\;\ell \leq 9.8 \cdot 10^{+119}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \end{array} \]
NOTE: kx should be positive before calling this function
NOTE: ky should be positive before calling this function
NOTE: kx and ky should be sorted in increasing order before calling this function.
(FPCore (l Om kx ky)
 :precision binary64
 (if (<= l 9e-31)
   1.0
   (if (<= l 50000000.0) (sqrt 0.5) (if (<= l 9.8e+119) 1.0 (sqrt 0.5)))))
kx = abs(kx);
ky = abs(ky);
assert(kx < ky);
double code(double l, double Om, double kx, double ky) {
	double tmp;
	if (l <= 9e-31) {
		tmp = 1.0;
	} else if (l <= 50000000.0) {
		tmp = sqrt(0.5);
	} else if (l <= 9.8e+119) {
		tmp = 1.0;
	} else {
		tmp = sqrt(0.5);
	}
	return tmp;
}
NOTE: kx should be positive before calling this function
NOTE: ky should be positive before calling this function
NOTE: kx and ky should be sorted in increasing order before calling this function.
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
    real(8) :: tmp
    if (l <= 9d-31) then
        tmp = 1.0d0
    else if (l <= 50000000.0d0) then
        tmp = sqrt(0.5d0)
    else if (l <= 9.8d+119) then
        tmp = 1.0d0
    else
        tmp = sqrt(0.5d0)
    end if
    code = tmp
end function
kx = Math.abs(kx);
ky = Math.abs(ky);
assert kx < ky;
public static double code(double l, double Om, double kx, double ky) {
	double tmp;
	if (l <= 9e-31) {
		tmp = 1.0;
	} else if (l <= 50000000.0) {
		tmp = Math.sqrt(0.5);
	} else if (l <= 9.8e+119) {
		tmp = 1.0;
	} else {
		tmp = Math.sqrt(0.5);
	}
	return tmp;
}
kx = abs(kx)
ky = abs(ky)
[kx, ky] = sort([kx, ky])
def code(l, Om, kx, ky):
	tmp = 0
	if l <= 9e-31:
		tmp = 1.0
	elif l <= 50000000.0:
		tmp = math.sqrt(0.5)
	elif l <= 9.8e+119:
		tmp = 1.0
	else:
		tmp = math.sqrt(0.5)
	return tmp
kx = abs(kx)
ky = abs(ky)
kx, ky = sort([kx, ky])
function code(l, Om, kx, ky)
	tmp = 0.0
	if (l <= 9e-31)
		tmp = 1.0;
	elseif (l <= 50000000.0)
		tmp = sqrt(0.5);
	elseif (l <= 9.8e+119)
		tmp = 1.0;
	else
		tmp = sqrt(0.5);
	end
	return tmp
end
kx = abs(kx)
ky = abs(ky)
kx, ky = num2cell(sort([kx, ky])){:}
function tmp_2 = code(l, Om, kx, ky)
	tmp = 0.0;
	if (l <= 9e-31)
		tmp = 1.0;
	elseif (l <= 50000000.0)
		tmp = sqrt(0.5);
	elseif (l <= 9.8e+119)
		tmp = 1.0;
	else
		tmp = sqrt(0.5);
	end
	tmp_2 = tmp;
end
NOTE: kx should be positive before calling this function
NOTE: ky should be positive before calling this function
NOTE: kx and ky should be sorted in increasing order before calling this function.
code[l_, Om_, kx_, ky_] := If[LessEqual[l, 9e-31], 1.0, If[LessEqual[l, 50000000.0], N[Sqrt[0.5], $MachinePrecision], If[LessEqual[l, 9.8e+119], 1.0, N[Sqrt[0.5], $MachinePrecision]]]]
\begin{array}{l}
kx = |kx|\\
ky = |ky|\\
[kx, ky] = \mathsf{sort}([kx, ky])\\
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 9 \cdot 10^{-31}:\\
\;\;\;\;1\\

\mathbf{elif}\;\ell \leq 50000000:\\
\;\;\;\;\sqrt{0.5}\\

\mathbf{elif}\;\ell \leq 9.8 \cdot 10^{+119}:\\
\;\;\;\;1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < 9.0000000000000008e-31 or 5e7 < l < 9.79999999999999992e119

    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. Step-by-step derivation
      1. distribute-rgt-in98.1%

        \[\leadsto \sqrt{\color{blue}{1 \cdot \frac{1}{2} + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}}} \]
      2. metadata-eval98.1%

        \[\leadsto \sqrt{1 \cdot \color{blue}{0.5} + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}} \]
      3. metadata-eval98.1%

        \[\leadsto \sqrt{\color{blue}{0.5} + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}} \]
      4. associate-/l*98.1%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + {\color{blue}{\left(\frac{2}{\frac{Om}{\ell}}\right)}}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}} \]
      5. metadata-eval98.1%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + {\left(\frac{2}{\frac{Om}{\ell}}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \color{blue}{0.5}} \]
    3. Simplified98.1%

      \[\leadsto \color{blue}{\sqrt{0.5 + \frac{1}{\sqrt{1 + {\left(\frac{2}{\frac{Om}{\ell}}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot 0.5}} \]
    4. Taylor expanded in kx around 0 77.9%

      \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + \color{blue}{4 \cdot \frac{{\ell}^{2} \cdot {\sin ky}^{2}}{{Om}^{2}}}}} \cdot 0.5} \]
    5. Step-by-step derivation
      1. associate-/l*78.4%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \color{blue}{\frac{{\ell}^{2}}{\frac{{Om}^{2}}{{\sin ky}^{2}}}}}} \cdot 0.5} \]
      2. associate-/r/78.3%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \color{blue}{\left(\frac{{\ell}^{2}}{{Om}^{2}} \cdot {\sin ky}^{2}\right)}}} \cdot 0.5} \]
      3. unpow278.3%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \left(\frac{\color{blue}{\ell \cdot \ell}}{{Om}^{2}} \cdot {\sin ky}^{2}\right)}} \cdot 0.5} \]
      4. unpow278.3%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \left(\frac{\ell \cdot \ell}{\color{blue}{Om \cdot Om}} \cdot {\sin ky}^{2}\right)}} \cdot 0.5} \]
      5. times-frac90.1%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \left(\color{blue}{\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right)} \cdot {\sin ky}^{2}\right)}} \cdot 0.5} \]
    6. Simplified90.1%

      \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + \color{blue}{4 \cdot \left(\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot {\sin ky}^{2}\right)}}} \cdot 0.5} \]
    7. Step-by-step derivation
      1. add-sqr-sqrt90.1%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + \color{blue}{\sqrt{4 \cdot \left(\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot {\sin ky}^{2}\right)} \cdot \sqrt{4 \cdot \left(\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot {\sin ky}^{2}\right)}}}} \cdot 0.5} \]
      2. hypot-1-def90.1%

        \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{\mathsf{hypot}\left(1, \sqrt{4 \cdot \left(\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot {\sin ky}^{2}\right)}\right)}} \cdot 0.5} \]
      3. sqrt-prod90.1%

        \[\leadsto \sqrt{0.5 + \frac{1}{\mathsf{hypot}\left(1, \color{blue}{\sqrt{4} \cdot \sqrt{\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot {\sin ky}^{2}}}\right)} \cdot 0.5} \]
      4. metadata-eval90.1%

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

        \[\leadsto \sqrt{0.5 + \frac{1}{\mathsf{hypot}\left(1, 2 \cdot \color{blue}{\left(\sqrt{\frac{\ell}{Om} \cdot \frac{\ell}{Om}} \cdot \sqrt{{\sin ky}^{2}}\right)}\right)} \cdot 0.5} \]
      6. sqrt-prod50.6%

        \[\leadsto \sqrt{0.5 + \frac{1}{\mathsf{hypot}\left(1, 2 \cdot \left(\color{blue}{\left(\sqrt{\frac{\ell}{Om}} \cdot \sqrt{\frac{\ell}{Om}}\right)} \cdot \sqrt{{\sin ky}^{2}}\right)\right)} \cdot 0.5} \]
      7. add-sqr-sqrt90.7%

        \[\leadsto \sqrt{0.5 + \frac{1}{\mathsf{hypot}\left(1, 2 \cdot \left(\color{blue}{\frac{\ell}{Om}} \cdot \sqrt{{\sin ky}^{2}}\right)\right)} \cdot 0.5} \]
      8. unpow290.7%

        \[\leadsto \sqrt{0.5 + \frac{1}{\mathsf{hypot}\left(1, 2 \cdot \left(\frac{\ell}{Om} \cdot \sqrt{\color{blue}{\sin ky \cdot \sin ky}}\right)\right)} \cdot 0.5} \]
      9. sqrt-prod46.1%

        \[\leadsto \sqrt{0.5 + \frac{1}{\mathsf{hypot}\left(1, 2 \cdot \left(\frac{\ell}{Om} \cdot \color{blue}{\left(\sqrt{\sin ky} \cdot \sqrt{\sin ky}\right)}\right)\right)} \cdot 0.5} \]
      10. add-sqr-sqrt95.1%

        \[\leadsto \sqrt{0.5 + \frac{1}{\mathsf{hypot}\left(1, 2 \cdot \left(\frac{\ell}{Om} \cdot \color{blue}{\sin ky}\right)\right)} \cdot 0.5} \]
    8. Applied egg-rr95.1%

      \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{\mathsf{hypot}\left(1, 2 \cdot \left(\frac{\ell}{Om} \cdot \sin ky\right)\right)}} \cdot 0.5} \]
    9. Taylor expanded in l around 0 70.8%

      \[\leadsto \sqrt{0.5 + \color{blue}{1} \cdot 0.5} \]

    if 9.0000000000000008e-31 < l < 5e7 or 9.79999999999999992e119 < l

    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. Step-by-step derivation
      1. distribute-rgt-in100.0%

        \[\leadsto \sqrt{\color{blue}{1 \cdot \frac{1}{2} + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}}} \]
      2. metadata-eval100.0%

        \[\leadsto \sqrt{1 \cdot \color{blue}{0.5} + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}} \]
      3. metadata-eval100.0%

        \[\leadsto \sqrt{\color{blue}{0.5} + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}} \]
      4. associate-/l*100.0%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + {\color{blue}{\left(\frac{2}{\frac{Om}{\ell}}\right)}}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}} \]
      5. metadata-eval100.0%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + {\left(\frac{2}{\frac{Om}{\ell}}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \color{blue}{0.5}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\sqrt{0.5 + \frac{1}{\sqrt{1 + {\left(\frac{2}{\frac{Om}{\ell}}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot 0.5}} \]
    4. Taylor expanded in Om around 0 84.1%

      \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{2 \cdot \left(\sqrt{{\sin ky}^{2} + {\sin kx}^{2}} \cdot \frac{\ell}{Om}\right)}} \cdot 0.5} \]
    5. Step-by-step derivation
      1. associate-*r*84.1%

        \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{\left(2 \cdot \sqrt{{\sin ky}^{2} + {\sin kx}^{2}}\right) \cdot \frac{\ell}{Om}}} \cdot 0.5} \]
      2. *-commutative84.1%

        \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{\left(\sqrt{{\sin ky}^{2} + {\sin kx}^{2}} \cdot 2\right)} \cdot \frac{\ell}{Om}} \cdot 0.5} \]
      3. associate-*r*84.1%

        \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{\sqrt{{\sin ky}^{2} + {\sin kx}^{2}} \cdot \left(2 \cdot \frac{\ell}{Om}\right)}} \cdot 0.5} \]
      4. unpow284.1%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}} \cdot \left(2 \cdot \frac{\ell}{Om}\right)} \cdot 0.5} \]
      5. unpow284.1%

        \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}} \cdot \left(2 \cdot \frac{\ell}{Om}\right)} \cdot 0.5} \]
      6. hypot-def84.1%

        \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(2 \cdot \frac{\ell}{Om}\right)} \cdot 0.5} \]
    6. Simplified84.1%

      \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right) \cdot \left(2 \cdot \frac{\ell}{Om}\right)}} \cdot 0.5} \]
    7. Taylor expanded in l around inf 86.2%

      \[\leadsto \color{blue}{\sqrt{0.5}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification73.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 9 \cdot 10^{-31}:\\ \;\;\;\;1\\ \mathbf{elif}\;\ell \leq 50000000:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{elif}\;\ell \leq 9.8 \cdot 10^{+119}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \]

Alternative 5: 56.2% accurate, 7.1× speedup?

\[\begin{array}{l} kx = |kx|\\ ky = |ky|\\ [kx, ky] = \mathsf{sort}([kx, ky])\\ \\ \sqrt{0.5} \end{array} \]
NOTE: kx should be positive before calling this function
NOTE: ky should be positive before calling this function
NOTE: kx and ky should be sorted in increasing order before calling this function.
(FPCore (l Om kx ky) :precision binary64 (sqrt 0.5))
kx = abs(kx);
ky = abs(ky);
assert(kx < ky);
double code(double l, double Om, double kx, double ky) {
	return sqrt(0.5);
}
NOTE: kx should be positive before calling this function
NOTE: ky should be positive before calling this function
NOTE: kx and ky should be sorted in increasing order before calling this function.
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(0.5d0)
end function
kx = Math.abs(kx);
ky = Math.abs(ky);
assert kx < ky;
public static double code(double l, double Om, double kx, double ky) {
	return Math.sqrt(0.5);
}
kx = abs(kx)
ky = abs(ky)
[kx, ky] = sort([kx, ky])
def code(l, Om, kx, ky):
	return math.sqrt(0.5)
kx = abs(kx)
ky = abs(ky)
kx, ky = sort([kx, ky])
function code(l, Om, kx, ky)
	return sqrt(0.5)
end
kx = abs(kx)
ky = abs(ky)
kx, ky = num2cell(sort([kx, ky])){:}
function tmp = code(l, Om, kx, ky)
	tmp = sqrt(0.5);
end
NOTE: kx should be positive before calling this function
NOTE: ky should be positive before calling this function
NOTE: kx and ky should be sorted in increasing order before calling this function.
code[l_, Om_, kx_, ky_] := N[Sqrt[0.5], $MachinePrecision]
\begin{array}{l}
kx = |kx|\\
ky = |ky|\\
[kx, ky] = \mathsf{sort}([kx, ky])\\
\\
\sqrt{0.5}
\end{array}
Derivation
  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. Step-by-step derivation
    1. distribute-rgt-in98.4%

      \[\leadsto \sqrt{\color{blue}{1 \cdot \frac{1}{2} + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}}} \]
    2. metadata-eval98.4%

      \[\leadsto \sqrt{1 \cdot \color{blue}{0.5} + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}} \]
    3. metadata-eval98.4%

      \[\leadsto \sqrt{\color{blue}{0.5} + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}} \]
    4. associate-/l*98.4%

      \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + {\color{blue}{\left(\frac{2}{\frac{Om}{\ell}}\right)}}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \frac{1}{2}} \]
    5. metadata-eval98.4%

      \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + {\left(\frac{2}{\frac{Om}{\ell}}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot \color{blue}{0.5}} \]
  3. Simplified98.4%

    \[\leadsto \color{blue}{\sqrt{0.5 + \frac{1}{\sqrt{1 + {\left(\frac{2}{\frac{Om}{\ell}}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}} \cdot 0.5}} \]
  4. Taylor expanded in Om around 0 44.1%

    \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{2 \cdot \left(\sqrt{{\sin ky}^{2} + {\sin kx}^{2}} \cdot \frac{\ell}{Om}\right)}} \cdot 0.5} \]
  5. Step-by-step derivation
    1. associate-*r*44.1%

      \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{\left(2 \cdot \sqrt{{\sin ky}^{2} + {\sin kx}^{2}}\right) \cdot \frac{\ell}{Om}}} \cdot 0.5} \]
    2. *-commutative44.1%

      \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{\left(\sqrt{{\sin ky}^{2} + {\sin kx}^{2}} \cdot 2\right)} \cdot \frac{\ell}{Om}} \cdot 0.5} \]
    3. associate-*r*44.1%

      \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{\sqrt{{\sin ky}^{2} + {\sin kx}^{2}} \cdot \left(2 \cdot \frac{\ell}{Om}\right)}} \cdot 0.5} \]
    4. unpow244.1%

      \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}} \cdot \left(2 \cdot \frac{\ell}{Om}\right)} \cdot 0.5} \]
    5. unpow244.1%

      \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}} \cdot \left(2 \cdot \frac{\ell}{Om}\right)} \cdot 0.5} \]
    6. hypot-def45.7%

      \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(2 \cdot \frac{\ell}{Om}\right)} \cdot 0.5} \]
  6. Simplified45.7%

    \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right) \cdot \left(2 \cdot \frac{\ell}{Om}\right)}} \cdot 0.5} \]
  7. Taylor expanded in l around inf 54.6%

    \[\leadsto \color{blue}{\sqrt{0.5}} \]
  8. Final simplification54.6%

    \[\leadsto \sqrt{0.5} \]

Reproduce

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