Toniolo and Linder, Equation (3a)

Percentage Accurate: 98.6% → 99.7%
Time: 11.8s
Alternatives: 7
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 7 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.6% 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, \sin ky \cdot \frac{2 \cdot \ell}{Om}\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 (* (sin ky) (/ (* 2.0 l) Om))))))))
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, (sin(ky) * ((2.0 * l) / Om)))))));
}
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, (Math.sin(ky) * ((2.0 * l) / Om)))))));
}
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, (math.sin(ky) * ((2.0 * l) / Om)))))))
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(sin(ky) * Float64(Float64(2.0 * l) / Om)))))))
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, (sin(ky) * ((2.0 * l) / Om)))))));
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[(N[Sin[ky], $MachinePrecision] * N[(N[(2.0 * l), $MachinePrecision] / Om), $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, \sin ky \cdot \frac{2 \cdot \ell}{Om}\right)}}
\end{array}
Derivation
  1. Initial program 99.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. Step-by-step derivation
    1. distribute-rgt-in99.2%

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

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

      \[\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*99.2%

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

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

    \[\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 81.2%

    \[\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*81.3%

      \[\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/82.2%

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

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

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

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

    \[\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. expm1-log1p-u90.8%

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

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

    \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{e^{\mathsf{log1p}\left(\mathsf{hypot}\left(1, 2 \cdot \left(\frac{\ell}{Om} \cdot \sin ky\right)\right)\right)} - 1}} \cdot 0.5} \]
  9. Step-by-step derivation
    1. expm1-def95.6%

      \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{hypot}\left(1, 2 \cdot \left(\frac{\ell}{Om} \cdot \sin ky\right)\right)\right)\right)}} \cdot 0.5} \]
    2. expm1-log1p95.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} \]
    3. *-commutative95.6%

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

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

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

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

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

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

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

Alternative 2: 71.3% accurate, 3.2× speedup?

\[\begin{array}{l} kx = |kx|\\ ky = |ky|\\ [kx, ky] = \mathsf{sort}([kx, ky])\\ \\ \begin{array}{l} \mathbf{if}\;Om \leq 5 \cdot 10^{-166}:\\ \;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{1}{2 \cdot \frac{ky \cdot \ell}{Om} + 0.25 \cdot \frac{Om}{ky \cdot \ell}}}\\ \mathbf{elif}\;Om \leq 10^{+122}:\\ \;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{1}{\sqrt{1 + 4 \cdot \frac{\left(ky \cdot \ell\right) \cdot \left(ky \cdot \ell\right)}{Om \cdot Om}}}}\\ \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 5e-166)
   (sqrt
    (+
     0.5
     (* 0.5 (/ 1.0 (+ (* 2.0 (/ (* ky l) Om)) (* 0.25 (/ Om (* ky l))))))))
   (if (<= Om 1e+122)
     (sqrt
      (+
       0.5
       (*
        0.5
        (/ 1.0 (sqrt (+ 1.0 (* 4.0 (/ (* (* ky l) (* ky l)) (* Om Om)))))))))
     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 <= 5e-166) {
		tmp = sqrt((0.5 + (0.5 * (1.0 / ((2.0 * ((ky * l) / Om)) + (0.25 * (Om / (ky * l))))))));
	} else if (Om <= 1e+122) {
		tmp = sqrt((0.5 + (0.5 * (1.0 / sqrt((1.0 + (4.0 * (((ky * l) * (ky * l)) / (Om * Om)))))))));
	} 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 <= 5d-166) then
        tmp = sqrt((0.5d0 + (0.5d0 * (1.0d0 / ((2.0d0 * ((ky * l) / om)) + (0.25d0 * (om / (ky * l))))))))
    else if (om <= 1d+122) then
        tmp = sqrt((0.5d0 + (0.5d0 * (1.0d0 / sqrt((1.0d0 + (4.0d0 * (((ky * l) * (ky * l)) / (om * om)))))))))
    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 <= 5e-166) {
		tmp = Math.sqrt((0.5 + (0.5 * (1.0 / ((2.0 * ((ky * l) / Om)) + (0.25 * (Om / (ky * l))))))));
	} else if (Om <= 1e+122) {
		tmp = Math.sqrt((0.5 + (0.5 * (1.0 / Math.sqrt((1.0 + (4.0 * (((ky * l) * (ky * l)) / (Om * Om)))))))));
	} 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 <= 5e-166:
		tmp = math.sqrt((0.5 + (0.5 * (1.0 / ((2.0 * ((ky * l) / Om)) + (0.25 * (Om / (ky * l))))))))
	elif Om <= 1e+122:
		tmp = math.sqrt((0.5 + (0.5 * (1.0 / math.sqrt((1.0 + (4.0 * (((ky * l) * (ky * l)) / (Om * Om)))))))))
	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 <= 5e-166)
		tmp = sqrt(Float64(0.5 + Float64(0.5 * Float64(1.0 / Float64(Float64(2.0 * Float64(Float64(ky * l) / Om)) + Float64(0.25 * Float64(Om / Float64(ky * l))))))));
	elseif (Om <= 1e+122)
		tmp = sqrt(Float64(0.5 + Float64(0.5 * Float64(1.0 / sqrt(Float64(1.0 + Float64(4.0 * Float64(Float64(Float64(ky * l) * Float64(ky * l)) / Float64(Om * Om)))))))));
	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 <= 5e-166)
		tmp = sqrt((0.5 + (0.5 * (1.0 / ((2.0 * ((ky * l) / Om)) + (0.25 * (Om / (ky * l))))))));
	elseif (Om <= 1e+122)
		tmp = sqrt((0.5 + (0.5 * (1.0 / sqrt((1.0 + (4.0 * (((ky * l) * (ky * l)) / (Om * Om)))))))));
	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, 5e-166], N[Sqrt[N[(0.5 + N[(0.5 * N[(1.0 / N[(N[(2.0 * N[(N[(ky * l), $MachinePrecision] / Om), $MachinePrecision]), $MachinePrecision] + N[(0.25 * N[(Om / N[(ky * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[Om, 1e+122], N[Sqrt[N[(0.5 + N[(0.5 * N[(1.0 / N[Sqrt[N[(1.0 + N[(4.0 * N[(N[(N[(ky * l), $MachinePrecision] * N[(ky * l), $MachinePrecision]), $MachinePrecision] / N[(Om * Om), $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 5 \cdot 10^{-166}:\\
\;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{1}{2 \cdot \frac{ky \cdot \ell}{Om} + 0.25 \cdot \frac{Om}{ky \cdot \ell}}}\\

\mathbf{elif}\;Om \leq 10^{+122}:\\
\;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{1}{\sqrt{1 + 4 \cdot \frac{\left(ky \cdot \ell\right) \cdot \left(ky \cdot \ell\right)}{Om \cdot Om}}}}\\

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


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

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

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

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

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

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

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

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

      \[\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*77.5%

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

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

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

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

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

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

      \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \color{blue}{\frac{{\ell}^{2} \cdot {ky}^{2}}{{Om}^{2}}}}} \cdot 0.5} \]
    8. Step-by-step derivation
      1. unpow259.5%

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

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

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

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

      \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \color{blue}{\frac{\left(\ell \cdot ky\right) \cdot \left(\ell \cdot ky\right)}{Om \cdot Om}}}} \cdot 0.5} \]
    10. Taylor expanded in l around inf 57.8%

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

    if 5e-166 < Om < 1.00000000000000001e122

    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 91.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*89.8%

        \[\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/91.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. unpow291.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. unpow291.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-frac90.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. Simplified90.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. Taylor expanded in ky around 0 76.2%

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

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

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

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

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

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

    if 1.00000000000000001e122 < 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 85.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*84.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/85.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. unpow285.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. unpow285.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-frac100.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. Simplified100.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. expm1-log1p-u100.0%

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

        \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{e^{\mathsf{log1p}\left(\sqrt{1 + 4 \cdot \left(\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot {\sin ky}^{2}\right)}\right)} - 1}} \cdot 0.5} \]
    8. Applied egg-rr100.0%

      \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{e^{\mathsf{log1p}\left(\mathsf{hypot}\left(1, 2 \cdot \left(\frac{\ell}{Om} \cdot \sin ky\right)\right)\right)} - 1}} \cdot 0.5} \]
    9. Step-by-step derivation
      1. expm1-def100.0%

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

        \[\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} \]
      3. *-commutative100.0%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;Om \leq 5 \cdot 10^{-166}:\\ \;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{1}{2 \cdot \frac{ky \cdot \ell}{Om} + 0.25 \cdot \frac{Om}{ky \cdot \ell}}}\\ \mathbf{elif}\;Om \leq 10^{+122}:\\ \;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{1}{\sqrt{1 + 4 \cdot \frac{\left(ky \cdot \ell\right) \cdot \left(ky \cdot \ell\right)}{Om \cdot Om}}}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]

Alternative 3: 69.1% accurate, 3.2× speedup?

\[\begin{array}{l} kx = |kx|\\ ky = |ky|\\ [kx, ky] = \mathsf{sort}([kx, ky])\\ \\ \begin{array}{l} \mathbf{if}\;Om \leq 1.7 \cdot 10^{-202}:\\ \;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{1}{2 \cdot \frac{ky \cdot \ell}{Om} + 0.25 \cdot \frac{Om}{ky \cdot \ell}}}\\ \mathbf{elif}\;Om \leq 1.15 \cdot 10^{-56}:\\ \;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{1}{\mathsf{fma}\left(2, \frac{\left(ky \cdot \ell\right) \cdot \left(ky \cdot \ell\right)}{Om \cdot Om}, 1\right)}}\\ \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 1.7e-202)
   (sqrt
    (+
     0.5
     (* 0.5 (/ 1.0 (+ (* 2.0 (/ (* ky l) Om)) (* 0.25 (/ Om (* ky l))))))))
   (if (<= Om 1.15e-56)
     (sqrt
      (+
       0.5
       (* 0.5 (/ 1.0 (fma 2.0 (/ (* (* ky l) (* ky l)) (* Om Om)) 1.0)))))
     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 <= 1.7e-202) {
		tmp = sqrt((0.5 + (0.5 * (1.0 / ((2.0 * ((ky * l) / Om)) + (0.25 * (Om / (ky * l))))))));
	} else if (Om <= 1.15e-56) {
		tmp = sqrt((0.5 + (0.5 * (1.0 / fma(2.0, (((ky * l) * (ky * l)) / (Om * Om)), 1.0)))));
	} 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 <= 1.7e-202)
		tmp = sqrt(Float64(0.5 + Float64(0.5 * Float64(1.0 / Float64(Float64(2.0 * Float64(Float64(ky * l) / Om)) + Float64(0.25 * Float64(Om / Float64(ky * l))))))));
	elseif (Om <= 1.15e-56)
		tmp = sqrt(Float64(0.5 + Float64(0.5 * Float64(1.0 / fma(2.0, Float64(Float64(Float64(ky * l) * Float64(ky * l)) / Float64(Om * Om)), 1.0)))));
	else
		tmp = 1.0;
	end
	return 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, 1.7e-202], N[Sqrt[N[(0.5 + N[(0.5 * N[(1.0 / N[(N[(2.0 * N[(N[(ky * l), $MachinePrecision] / Om), $MachinePrecision]), $MachinePrecision] + N[(0.25 * N[(Om / N[(ky * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[Om, 1.15e-56], N[Sqrt[N[(0.5 + N[(0.5 * N[(1.0 / N[(2.0 * N[(N[(N[(ky * l), $MachinePrecision] * N[(ky * l), $MachinePrecision]), $MachinePrecision] / N[(Om * Om), $MachinePrecision]), $MachinePrecision] + 1.0), $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 1.7 \cdot 10^{-202}:\\
\;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{1}{2 \cdot \frac{ky \cdot \ell}{Om} + 0.25 \cdot \frac{Om}{ky \cdot \ell}}}\\

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

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


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

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

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

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

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

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

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

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

      \[\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*77.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/78.2%

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

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

        \[\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-frac88.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. Simplified88.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. Taylor expanded in ky around 0 59.1%

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

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

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

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

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

      \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \color{blue}{\frac{\left(\ell \cdot ky\right) \cdot \left(\ell \cdot ky\right)}{Om \cdot Om}}}} \cdot 0.5} \]
    10. Taylor expanded in l around inf 57.3%

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

    if 1.70000000000000006e-202 < Om < 1.15000000000000001e-56

    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 82.4%

      \[\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*82.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/82.4%

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

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

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

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

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

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

        \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{2 \cdot \frac{{\ell}^{2} \cdot {ky}^{2}}{{Om}^{2}} + 1}} \cdot 0.5} \]
      2. fma-def78.4%

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

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

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

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

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

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

    if 1.15000000000000001e-56 < 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 90.1%

      \[\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*88.3%

        \[\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/90.1%

        \[\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. unpow290.1%

        \[\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. unpow290.1%

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

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

      \[\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. expm1-log1p-u97.9%

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

        \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{e^{\mathsf{log1p}\left(\sqrt{1 + 4 \cdot \left(\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot {\sin ky}^{2}\right)}\right)} - 1}} \cdot 0.5} \]
    8. Applied egg-rr97.9%

      \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{e^{\mathsf{log1p}\left(\mathsf{hypot}\left(1, 2 \cdot \left(\frac{\ell}{Om} \cdot \sin ky\right)\right)\right)} - 1}} \cdot 0.5} \]
    9. Step-by-step derivation
      1. expm1-def97.9%

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

        \[\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} \]
      3. *-commutative97.9%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;Om \leq 1.7 \cdot 10^{-202}:\\ \;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{1}{2 \cdot \frac{ky \cdot \ell}{Om} + 0.25 \cdot \frac{Om}{ky \cdot \ell}}}\\ \mathbf{elif}\;Om \leq 1.15 \cdot 10^{-56}:\\ \;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{1}{\mathsf{fma}\left(2, \frac{\left(ky \cdot \ell\right) \cdot \left(ky \cdot \ell\right)}{Om \cdot Om}, 1\right)}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]

Alternative 4: 68.6% accurate, 5.8× speedup?

\[\begin{array}{l} kx = |kx|\\ ky = |ky|\\ [kx, ky] = \mathsf{sort}([kx, ky])\\ \\ \begin{array}{l} \mathbf{if}\;Om \leq 8.2 \cdot 10^{-139}:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{elif}\;Om \leq 1.1 \cdot 10^{-56}:\\ \;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{1}{1 + 2 \cdot \frac{\ell \cdot \ell}{\frac{Om \cdot Om}{ky \cdot ky}}}}\\ \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 8.2e-139)
   (sqrt 0.5)
   (if (<= Om 1.1e-56)
     (sqrt
      (+
       0.5
       (* 0.5 (/ 1.0 (+ 1.0 (* 2.0 (/ (* l l) (/ (* Om Om) (* ky ky)))))))))
     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 <= 8.2e-139) {
		tmp = sqrt(0.5);
	} else if (Om <= 1.1e-56) {
		tmp = sqrt((0.5 + (0.5 * (1.0 / (1.0 + (2.0 * ((l * l) / ((Om * Om) / (ky * ky)))))))));
	} 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 <= 8.2d-139) then
        tmp = sqrt(0.5d0)
    else if (om <= 1.1d-56) then
        tmp = sqrt((0.5d0 + (0.5d0 * (1.0d0 / (1.0d0 + (2.0d0 * ((l * l) / ((om * om) / (ky * ky)))))))))
    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 <= 8.2e-139) {
		tmp = Math.sqrt(0.5);
	} else if (Om <= 1.1e-56) {
		tmp = Math.sqrt((0.5 + (0.5 * (1.0 / (1.0 + (2.0 * ((l * l) / ((Om * Om) / (ky * ky)))))))));
	} 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 <= 8.2e-139:
		tmp = math.sqrt(0.5)
	elif Om <= 1.1e-56:
		tmp = math.sqrt((0.5 + (0.5 * (1.0 / (1.0 + (2.0 * ((l * l) / ((Om * Om) / (ky * ky)))))))))
	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 <= 8.2e-139)
		tmp = sqrt(0.5);
	elseif (Om <= 1.1e-56)
		tmp = sqrt(Float64(0.5 + Float64(0.5 * Float64(1.0 / Float64(1.0 + Float64(2.0 * Float64(Float64(l * l) / Float64(Float64(Om * Om) / Float64(ky * ky)))))))));
	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 <= 8.2e-139)
		tmp = sqrt(0.5);
	elseif (Om <= 1.1e-56)
		tmp = sqrt((0.5 + (0.5 * (1.0 / (1.0 + (2.0 * ((l * l) / ((Om * Om) / (ky * ky)))))))));
	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, 8.2e-139], N[Sqrt[0.5], $MachinePrecision], If[LessEqual[Om, 1.1e-56], N[Sqrt[N[(0.5 + N[(0.5 * N[(1.0 / N[(1.0 + N[(2.0 * N[(N[(l * l), $MachinePrecision] / N[(N[(Om * Om), $MachinePrecision] / N[(ky * ky), $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 8.2 \cdot 10^{-139}:\\
\;\;\;\;\sqrt{0.5}\\

\mathbf{elif}\;Om \leq 1.1 \cdot 10^{-56}:\\
\;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{1}{1 + 2 \cdot \frac{\ell \cdot \ell}{\frac{Om \cdot Om}{ky \cdot ky}}}}\\

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


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

    1. Initial program 98.8%

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

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

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

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

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

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

      \[\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 50.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*50.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. *-commutative50.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*50.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. unpow250.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. unpow250.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-def51.2%

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

      \[\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 59.4%

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

    if 8.20000000000000028e-139 < Om < 1.10000000000000002e-56

    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 77.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*77.3%

        \[\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/77.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. unpow277.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. unpow277.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-frac77.3%

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

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

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

        \[\leadsto \sqrt{0.5 + \frac{1}{1 + 2 \cdot \color{blue}{\frac{{\ell}^{2}}{\frac{{Om}^{2}}{{ky}^{2}}}}} \cdot 0.5} \]
      2. unpow264.0%

        \[\leadsto \sqrt{0.5 + \frac{1}{1 + 2 \cdot \frac{\color{blue}{\ell \cdot \ell}}{\frac{{Om}^{2}}{{ky}^{2}}}} \cdot 0.5} \]
      3. unpow264.0%

        \[\leadsto \sqrt{0.5 + \frac{1}{1 + 2 \cdot \frac{\ell \cdot \ell}{\frac{\color{blue}{Om \cdot Om}}{{ky}^{2}}}} \cdot 0.5} \]
      4. unpow264.0%

        \[\leadsto \sqrt{0.5 + \frac{1}{1 + 2 \cdot \frac{\ell \cdot \ell}{\frac{Om \cdot Om}{\color{blue}{ky \cdot ky}}}} \cdot 0.5} \]
    9. Simplified64.0%

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

    if 1.10000000000000002e-56 < 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 90.1%

      \[\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*88.3%

        \[\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/90.1%

        \[\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. unpow290.1%

        \[\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. unpow290.1%

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

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

      \[\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. expm1-log1p-u97.9%

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

        \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{e^{\mathsf{log1p}\left(\sqrt{1 + 4 \cdot \left(\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot {\sin ky}^{2}\right)}\right)} - 1}} \cdot 0.5} \]
    8. Applied egg-rr97.9%

      \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{e^{\mathsf{log1p}\left(\mathsf{hypot}\left(1, 2 \cdot \left(\frac{\ell}{Om} \cdot \sin ky\right)\right)\right)} - 1}} \cdot 0.5} \]
    9. Step-by-step derivation
      1. expm1-def97.9%

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

        \[\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} \]
      3. *-commutative97.9%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;Om \leq 8.2 \cdot 10^{-139}:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{elif}\;Om \leq 1.1 \cdot 10^{-56}:\\ \;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{1}{1 + 2 \cdot \frac{\ell \cdot \ell}{\frac{Om \cdot Om}{ky \cdot ky}}}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]

Alternative 5: 68.6% accurate, 5.8× speedup?

\[\begin{array}{l} kx = |kx|\\ ky = |ky|\\ [kx, ky] = \mathsf{sort}([kx, ky])\\ \\ \begin{array}{l} \mathbf{if}\;Om \leq 1.26 \cdot 10^{-138}:\\ \;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{1}{2 \cdot \frac{ky \cdot \ell}{Om} + 0.25 \cdot \frac{Om}{ky \cdot \ell}}}\\ \mathbf{elif}\;Om \leq 1.15 \cdot 10^{-56}:\\ \;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{1}{1 + 2 \cdot \frac{\ell \cdot \ell}{\frac{Om \cdot Om}{ky \cdot ky}}}}\\ \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 1.26e-138)
   (sqrt
    (+
     0.5
     (* 0.5 (/ 1.0 (+ (* 2.0 (/ (* ky l) Om)) (* 0.25 (/ Om (* ky l))))))))
   (if (<= Om 1.15e-56)
     (sqrt
      (+
       0.5
       (* 0.5 (/ 1.0 (+ 1.0 (* 2.0 (/ (* l l) (/ (* Om Om) (* ky ky)))))))))
     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 <= 1.26e-138) {
		tmp = sqrt((0.5 + (0.5 * (1.0 / ((2.0 * ((ky * l) / Om)) + (0.25 * (Om / (ky * l))))))));
	} else if (Om <= 1.15e-56) {
		tmp = sqrt((0.5 + (0.5 * (1.0 / (1.0 + (2.0 * ((l * l) / ((Om * Om) / (ky * ky)))))))));
	} 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 <= 1.26d-138) then
        tmp = sqrt((0.5d0 + (0.5d0 * (1.0d0 / ((2.0d0 * ((ky * l) / om)) + (0.25d0 * (om / (ky * l))))))))
    else if (om <= 1.15d-56) then
        tmp = sqrt((0.5d0 + (0.5d0 * (1.0d0 / (1.0d0 + (2.0d0 * ((l * l) / ((om * om) / (ky * ky)))))))))
    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 <= 1.26e-138) {
		tmp = Math.sqrt((0.5 + (0.5 * (1.0 / ((2.0 * ((ky * l) / Om)) + (0.25 * (Om / (ky * l))))))));
	} else if (Om <= 1.15e-56) {
		tmp = Math.sqrt((0.5 + (0.5 * (1.0 / (1.0 + (2.0 * ((l * l) / ((Om * Om) / (ky * ky)))))))));
	} 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 <= 1.26e-138:
		tmp = math.sqrt((0.5 + (0.5 * (1.0 / ((2.0 * ((ky * l) / Om)) + (0.25 * (Om / (ky * l))))))))
	elif Om <= 1.15e-56:
		tmp = math.sqrt((0.5 + (0.5 * (1.0 / (1.0 + (2.0 * ((l * l) / ((Om * Om) / (ky * ky)))))))))
	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 <= 1.26e-138)
		tmp = sqrt(Float64(0.5 + Float64(0.5 * Float64(1.0 / Float64(Float64(2.0 * Float64(Float64(ky * l) / Om)) + Float64(0.25 * Float64(Om / Float64(ky * l))))))));
	elseif (Om <= 1.15e-56)
		tmp = sqrt(Float64(0.5 + Float64(0.5 * Float64(1.0 / Float64(1.0 + Float64(2.0 * Float64(Float64(l * l) / Float64(Float64(Om * Om) / Float64(ky * ky)))))))));
	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 <= 1.26e-138)
		tmp = sqrt((0.5 + (0.5 * (1.0 / ((2.0 * ((ky * l) / Om)) + (0.25 * (Om / (ky * l))))))));
	elseif (Om <= 1.15e-56)
		tmp = sqrt((0.5 + (0.5 * (1.0 / (1.0 + (2.0 * ((l * l) / ((Om * Om) / (ky * ky)))))))));
	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, 1.26e-138], N[Sqrt[N[(0.5 + N[(0.5 * N[(1.0 / N[(N[(2.0 * N[(N[(ky * l), $MachinePrecision] / Om), $MachinePrecision]), $MachinePrecision] + N[(0.25 * N[(Om / N[(ky * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[Om, 1.15e-56], N[Sqrt[N[(0.5 + N[(0.5 * N[(1.0 / N[(1.0 + N[(2.0 * N[(N[(l * l), $MachinePrecision] / N[(N[(Om * Om), $MachinePrecision] / N[(ky * ky), $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 1.26 \cdot 10^{-138}:\\
\;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{1}{2 \cdot \frac{ky \cdot \ell}{Om} + 0.25 \cdot \frac{Om}{ky \cdot \ell}}}\\

\mathbf{elif}\;Om \leq 1.15 \cdot 10^{-56}:\\
\;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{1}{1 + 2 \cdot \frac{\ell \cdot \ell}{\frac{Om \cdot Om}{ky \cdot ky}}}}\\

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


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

    1. Initial program 98.8%

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

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

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

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

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

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

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

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

        \[\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.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. unpow278.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. unpow278.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-frac88.8%

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

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

      \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \color{blue}{\frac{{\ell}^{2} \cdot {ky}^{2}}{{Om}^{2}}}}} \cdot 0.5} \]
    8. Step-by-step derivation
      1. unpow261.0%

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

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

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

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

      \[\leadsto \sqrt{0.5 + \frac{1}{\sqrt{1 + 4 \cdot \color{blue}{\frac{\left(\ell \cdot ky\right) \cdot \left(\ell \cdot ky\right)}{Om \cdot Om}}}} \cdot 0.5} \]
    10. Taylor expanded in l around inf 59.4%

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

    if 1.26e-138 < Om < 1.15000000000000001e-56

    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 77.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*77.3%

        \[\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/77.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. unpow277.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. unpow277.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-frac77.3%

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

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

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

        \[\leadsto \sqrt{0.5 + \frac{1}{1 + 2 \cdot \color{blue}{\frac{{\ell}^{2}}{\frac{{Om}^{2}}{{ky}^{2}}}}} \cdot 0.5} \]
      2. unpow264.0%

        \[\leadsto \sqrt{0.5 + \frac{1}{1 + 2 \cdot \frac{\color{blue}{\ell \cdot \ell}}{\frac{{Om}^{2}}{{ky}^{2}}}} \cdot 0.5} \]
      3. unpow264.0%

        \[\leadsto \sqrt{0.5 + \frac{1}{1 + 2 \cdot \frac{\ell \cdot \ell}{\frac{\color{blue}{Om \cdot Om}}{{ky}^{2}}}} \cdot 0.5} \]
      4. unpow264.0%

        \[\leadsto \sqrt{0.5 + \frac{1}{1 + 2 \cdot \frac{\ell \cdot \ell}{\frac{Om \cdot Om}{\color{blue}{ky \cdot ky}}}} \cdot 0.5} \]
    9. Simplified64.0%

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

    if 1.15000000000000001e-56 < 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 90.1%

      \[\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*88.3%

        \[\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/90.1%

        \[\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. unpow290.1%

        \[\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. unpow290.1%

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

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

      \[\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. expm1-log1p-u97.9%

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

        \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{e^{\mathsf{log1p}\left(\sqrt{1 + 4 \cdot \left(\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot {\sin ky}^{2}\right)}\right)} - 1}} \cdot 0.5} \]
    8. Applied egg-rr97.9%

      \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{e^{\mathsf{log1p}\left(\mathsf{hypot}\left(1, 2 \cdot \left(\frac{\ell}{Om} \cdot \sin ky\right)\right)\right)} - 1}} \cdot 0.5} \]
    9. Step-by-step derivation
      1. expm1-def97.9%

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

        \[\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} \]
      3. *-commutative97.9%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;Om \leq 1.26 \cdot 10^{-138}:\\ \;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{1}{2 \cdot \frac{ky \cdot \ell}{Om} + 0.25 \cdot \frac{Om}{ky \cdot \ell}}}\\ \mathbf{elif}\;Om \leq 1.15 \cdot 10^{-56}:\\ \;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{1}{1 + 2 \cdot \frac{\ell \cdot \ell}{\frac{Om \cdot Om}{ky \cdot ky}}}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]

Alternative 6: 67.5% accurate, 6.7× speedup?

\[\begin{array}{l} kx = |kx|\\ ky = |ky|\\ [kx, ky] = \mathsf{sort}([kx, ky])\\ \\ \begin{array}{l} \mathbf{if}\;Om \leq 5 \cdot 10^{-108}:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{elif}\;Om \leq 1.6 \cdot 10^{-82}:\\ \;\;\;\;1\\ \mathbf{elif}\;Om \leq 1.05 \cdot 10^{-56}:\\ \;\;\;\;\sqrt{0.5}\\ \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 5e-108)
   (sqrt 0.5)
   (if (<= Om 1.6e-82) 1.0 (if (<= Om 1.05e-56) (sqrt 0.5) 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 <= 5e-108) {
		tmp = sqrt(0.5);
	} else if (Om <= 1.6e-82) {
		tmp = 1.0;
	} else if (Om <= 1.05e-56) {
		tmp = sqrt(0.5);
	} 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 <= 5d-108) then
        tmp = sqrt(0.5d0)
    else if (om <= 1.6d-82) then
        tmp = 1.0d0
    else if (om <= 1.05d-56) then
        tmp = sqrt(0.5d0)
    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 <= 5e-108) {
		tmp = Math.sqrt(0.5);
	} else if (Om <= 1.6e-82) {
		tmp = 1.0;
	} else if (Om <= 1.05e-56) {
		tmp = Math.sqrt(0.5);
	} 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 <= 5e-108:
		tmp = math.sqrt(0.5)
	elif Om <= 1.6e-82:
		tmp = 1.0
	elif Om <= 1.05e-56:
		tmp = math.sqrt(0.5)
	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 <= 5e-108)
		tmp = sqrt(0.5);
	elseif (Om <= 1.6e-82)
		tmp = 1.0;
	elseif (Om <= 1.05e-56)
		tmp = sqrt(0.5);
	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 <= 5e-108)
		tmp = sqrt(0.5);
	elseif (Om <= 1.6e-82)
		tmp = 1.0;
	elseif (Om <= 1.05e-56)
		tmp = sqrt(0.5);
	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, 5e-108], N[Sqrt[0.5], $MachinePrecision], If[LessEqual[Om, 1.6e-82], 1.0, If[LessEqual[Om, 1.05e-56], N[Sqrt[0.5], $MachinePrecision], 1.0]]]
\begin{array}{l}
kx = |kx|\\
ky = |ky|\\
[kx, ky] = \mathsf{sort}([kx, ky])\\
\\
\begin{array}{l}
\mathbf{if}\;Om \leq 5 \cdot 10^{-108}:\\
\;\;\;\;\sqrt{0.5}\\

\mathbf{elif}\;Om \leq 1.6 \cdot 10^{-82}:\\
\;\;\;\;1\\

\mathbf{elif}\;Om \leq 1.05 \cdot 10^{-56}:\\
\;\;\;\;\sqrt{0.5}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if Om < 5e-108 or 1.6000000000000001e-82 < Om < 1.05000000000000003e-56

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5e-108 < Om < 1.6000000000000001e-82 or 1.05000000000000003e-56 < 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 90.5%

      \[\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*88.8%

        \[\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/90.5%

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

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

        \[\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-frac98.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. Simplified98.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. expm1-log1p-u98.0%

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

        \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{e^{\mathsf{log1p}\left(\sqrt{1 + 4 \cdot \left(\left(\frac{\ell}{Om} \cdot \frac{\ell}{Om}\right) \cdot {\sin ky}^{2}\right)}\right)} - 1}} \cdot 0.5} \]
    8. Applied egg-rr98.0%

      \[\leadsto \sqrt{0.5 + \frac{1}{\color{blue}{e^{\mathsf{log1p}\left(\mathsf{hypot}\left(1, 2 \cdot \left(\frac{\ell}{Om} \cdot \sin ky\right)\right)\right)} - 1}} \cdot 0.5} \]
    9. Step-by-step derivation
      1. expm1-def98.0%

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

        \[\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} \]
      3. *-commutative98.0%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;Om \leq 5 \cdot 10^{-108}:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{elif}\;Om \leq 1.6 \cdot 10^{-82}:\\ \;\;\;\;1\\ \mathbf{elif}\;Om \leq 1.05 \cdot 10^{-56}:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]

Alternative 7: 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 99.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. Step-by-step derivation
    1. distribute-rgt-in99.2%

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

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

      \[\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*99.2%

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

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

    \[\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 40.4%

    \[\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*40.4%

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

      \[\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*40.4%

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

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

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

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

    \[\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 51.1%

    \[\leadsto \color{blue}{\sqrt{0.5}} \]
  8. Final simplification51.1%

    \[\leadsto \sqrt{0.5} \]

Reproduce

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