Toniolo and Linder, Equation (3a)

Percentage Accurate: 98.4% → 99.6%
Time: 13.2s
Alternatives: 8
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 8 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.4% accurate, 1.0× speedup?

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

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

Alternative 1: 99.6% accurate, 1.7× speedup?

\[\begin{array}{l} kx = |kx|\\ ky = |ky|\\ [kx, ky] = \mathsf{sort}([kx, ky])\\ \\ \sqrt{0.5 + 0.5 \cdot \frac{1}{\sqrt{1 + 4 \cdot {\left(\frac{\ell}{Om} \cdot \sin ky\right)}^{2}}}} \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 (sqrt (+ 1.0 (* 4.0 (pow (* (/ l Om) (sin ky)) 2.0)))))))))
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 / sqrt((1.0 + (4.0 * pow(((l / Om) * sin(ky)), 2.0))))))));
}
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 + (0.5d0 * (1.0d0 / sqrt((1.0d0 + (4.0d0 * (((l / om) * sin(ky)) ** 2.0d0))))))))
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 + (0.5 * (1.0 / Math.sqrt((1.0 + (4.0 * Math.pow(((l / Om) * Math.sin(ky)), 2.0))))))));
}
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.sqrt((1.0 + (4.0 * math.pow(((l / Om) * math.sin(ky)), 2.0))))))))
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 / sqrt(Float64(1.0 + Float64(4.0 * (Float64(Float64(l / Om) * sin(ky)) ^ 2.0))))))))
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 / sqrt((1.0 + (4.0 * (((l / Om) * sin(ky)) ^ 2.0))))))));
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[N[(1.0 + N[(4.0 * N[Power[N[(N[(l / Om), $MachinePrecision] * N[Sin[ky], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $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}{\sqrt{1 + 4 \cdot {\left(\frac{\ell}{Om} \cdot \sin ky\right)}^{2}}}}
\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. Simplified99.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 99.6% accurate, 2.3× speedup?

\[\begin{array}{l} kx = |kx|\\ ky = |ky|\\ [kx, ky] = \mathsf{sort}([kx, ky])\\ \\ \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, \frac{\ell}{Om} \cdot \left(\sin ky \cdot 2\right)\right)}} \end{array} \]
NOTE: kx should be positive before calling this function
NOTE: ky should be positive before calling this function
NOTE: kx and ky should be sorted in increasing order before calling this function.
(FPCore (l Om kx ky)
 :precision binary64
 (sqrt (+ 0.5 (/ 0.5 (hypot 1.0 (* (/ l Om) (* (sin ky) 2.0)))))))
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 / hypot(1.0, ((l / Om) * (sin(ky) * 2.0))))));
}
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 / Math.hypot(1.0, ((l / Om) * (Math.sin(ky) * 2.0))))));
}
kx = abs(kx)
ky = abs(ky)
[kx, ky] = sort([kx, ky])
def code(l, Om, kx, ky):
	return math.sqrt((0.5 + (0.5 / math.hypot(1.0, ((l / Om) * (math.sin(ky) * 2.0))))))
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 / hypot(1.0, Float64(Float64(l / Om) * Float64(sin(ky) * 2.0))))))
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 / hypot(1.0, ((l / Om) * (sin(ky) * 2.0))))));
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[Sqrt[1.0 ^ 2 + N[(N[(l / Om), $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
kx = |kx|\\
ky = |ky|\\
[kx, ky] = \mathsf{sort}([kx, ky])\\
\\
\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, \frac{\ell}{Om} \cdot \left(\sin ky \cdot 2\right)\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. Simplified99.2%

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

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

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

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

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

    \[\leadsto \sqrt{0.5 + 0.5 \cdot \frac{1}{\color{blue}{\sqrt{1 + 4 \cdot \frac{\ell \cdot \ell}{\frac{Om \cdot Om}{{\sin ky}^{2}}}}}}} \]
  6. Step-by-step derivation
    1. expm1-log1p-u79.2%

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

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

    \[\leadsto \sqrt{0.5 + 0.5 \cdot \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}}} \]
  8. Step-by-step derivation
    1. expm1-def92.4%

      \[\leadsto \sqrt{0.5 + 0.5 \cdot \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)}}} \]
    2. expm1-log1p92.4%

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

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

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

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

    \[\leadsto \sqrt{0.5 + 0.5 \cdot \frac{1}{\color{blue}{\mathsf{hypot}\left(1, \sin ky \cdot \left(\frac{\ell}{Om} \cdot 2\right)\right)}}} \]
  10. Step-by-step derivation
    1. clear-num92.4%

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

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

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

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

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

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

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

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

Alternative 3: 66.6% accurate, 6.7× speedup?

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

\mathbf{elif}\;Om \leq 5.8 \cdot 10^{-73}:\\
\;\;\;\;1\\

\mathbf{elif}\;Om \leq 4.4 \cdot 10^{+32}:\\
\;\;\;\;\sqrt{0.5}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if Om < 3.99999999999999995e-92 or 5.8e-73 < Om < 4.40000000000000002e32

    1. Initial program 99.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. Simplified99.0%

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

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

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

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

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

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

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

    if 3.99999999999999995e-92 < Om < 5.8e-73 or 4.40000000000000002e32 < 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. Simplified100.0%

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

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

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

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

        \[\leadsto \sqrt{0.5 + 0.5 \cdot \frac{1}{\sqrt{1 + 4 \cdot \frac{\ell \cdot \ell}{\frac{\color{blue}{Om \cdot Om}}{{\sin ky}^{2}}}}}} \]
    5. Simplified87.9%

      \[\leadsto \sqrt{0.5 + 0.5 \cdot \frac{1}{\color{blue}{\sqrt{1 + 4 \cdot \frac{\ell \cdot \ell}{\frac{Om \cdot Om}{{\sin ky}^{2}}}}}}} \]
    6. Step-by-step derivation
      1. expm1-log1p-u87.9%

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

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

      \[\leadsto \sqrt{0.5 + 0.5 \cdot \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}}} \]
    8. Step-by-step derivation
      1. expm1-def95.7%

        \[\leadsto \sqrt{0.5 + 0.5 \cdot \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)}}} \]
      2. expm1-log1p95.7%

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

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

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

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

      \[\leadsto \sqrt{0.5 + 0.5 \cdot \frac{1}{\color{blue}{\mathsf{hypot}\left(1, \sin ky \cdot \left(\frac{\ell}{Om} \cdot 2\right)\right)}}} \]
    10. Step-by-step derivation
      1. clear-num95.7%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;Om \leq 4 \cdot 10^{-92}:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{elif}\;Om \leq 5.8 \cdot 10^{-73}:\\ \;\;\;\;1\\ \mathbf{elif}\;Om \leq 4.4 \cdot 10^{+32}:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]

Alternative 4: 61.7% accurate, 7.0× speedup?

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

\mathbf{else}:\\
\;\;\;\;1 + \frac{\ell \cdot \ell}{\frac{Om \cdot Om}{ky} \cdot \frac{1}{ky}} \cdot -0.5\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if Om < 2.6e131

    1. Initial program 99.1%

      \[\sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}}\right)} \]
    2. Simplified99.1%

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

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

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

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

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

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

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

    if 2.6e131 < Om

    1. Initial program 99.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. Simplified99.9%

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

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

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

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

        \[\leadsto \sqrt{0.5 + 0.5 \cdot \frac{1}{\sqrt{1 + 4 \cdot \frac{\ell \cdot \ell}{\frac{\color{blue}{Om \cdot Om}}{{\sin ky}^{2}}}}}} \]
    5. Simplified89.7%

      \[\leadsto \sqrt{0.5 + 0.5 \cdot \frac{1}{\color{blue}{\sqrt{1 + 4 \cdot \frac{\ell \cdot \ell}{\frac{Om \cdot Om}{{\sin ky}^{2}}}}}}} \]
    6. Step-by-step derivation
      1. expm1-log1p-u89.7%

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

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

      \[\leadsto \sqrt{0.5 + 0.5 \cdot \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}}} \]
    8. Step-by-step derivation
      1. expm1-def99.9%

        \[\leadsto \sqrt{0.5 + 0.5 \cdot \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)}}} \]
      2. expm1-log1p99.9%

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

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

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

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

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

      \[\leadsto \color{blue}{1 + -0.5 \cdot \frac{{\ell}^{2} \cdot {ky}^{2}}{{Om}^{2}}} \]
    11. Step-by-step derivation
      1. *-commutative58.6%

        \[\leadsto 1 + \color{blue}{\frac{{\ell}^{2} \cdot {ky}^{2}}{{Om}^{2}} \cdot -0.5} \]
      2. associate-/l*62.1%

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

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

        \[\leadsto 1 + \frac{\ell \cdot \ell}{\frac{\color{blue}{Om \cdot Om}}{{ky}^{2}}} \cdot -0.5 \]
      5. unpow262.1%

        \[\leadsto 1 + \frac{\ell \cdot \ell}{\frac{Om \cdot Om}{\color{blue}{ky \cdot ky}}} \cdot -0.5 \]
    12. Simplified62.1%

      \[\leadsto \color{blue}{1 + \frac{\ell \cdot \ell}{\frac{Om \cdot Om}{ky \cdot ky}} \cdot -0.5} \]
    13. Step-by-step derivation
      1. associate-/r*89.7%

        \[\leadsto 1 + \frac{\ell \cdot \ell}{\color{blue}{\frac{\frac{Om \cdot Om}{ky}}{ky}}} \cdot -0.5 \]
      2. div-inv89.7%

        \[\leadsto 1 + \frac{\ell \cdot \ell}{\color{blue}{\frac{Om \cdot Om}{ky} \cdot \frac{1}{ky}}} \cdot -0.5 \]
    14. Applied egg-rr89.7%

      \[\leadsto 1 + \frac{\ell \cdot \ell}{\color{blue}{\frac{Om \cdot Om}{ky} \cdot \frac{1}{ky}}} \cdot -0.5 \]
  3. Recombined 2 regimes into one program.
  4. Final simplification70.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;Om \leq 2.6 \cdot 10^{+131}:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{\ell \cdot \ell}{\frac{Om \cdot Om}{ky} \cdot \frac{1}{ky}} \cdot -0.5\\ \end{array} \]

Alternative 5: 39.0% accurate, 37.9× speedup?

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

\mathbf{else}:\\
\;\;\;\;1 + \frac{\ell \cdot \ell}{\frac{Om \cdot Om}{ky} \cdot \frac{1}{ky}} \cdot -0.5\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if Om < 2.00000000000000007e121

    1. Initial program 99.1%

      \[\sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}}\right)} \]
    2. Simplified99.1%

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

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

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

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

        \[\leadsto \sqrt{0.5 + 0.5 \cdot \frac{1}{\sqrt{1 + 4 \cdot \frac{\ell \cdot \ell}{\frac{\color{blue}{Om \cdot Om}}{{\sin ky}^{2}}}}}} \]
    5. Simplified77.7%

      \[\leadsto \sqrt{0.5 + 0.5 \cdot \frac{1}{\color{blue}{\sqrt{1 + 4 \cdot \frac{\ell \cdot \ell}{\frac{Om \cdot Om}{{\sin ky}^{2}}}}}}} \]
    6. Step-by-step derivation
      1. expm1-log1p-u77.7%

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

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

      \[\leadsto \sqrt{0.5 + 0.5 \cdot \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}}} \]
    8. Step-by-step derivation
      1. expm1-def91.4%

        \[\leadsto \sqrt{0.5 + 0.5 \cdot \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)}}} \]
      2. expm1-log1p91.4%

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

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

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

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

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

      \[\leadsto \color{blue}{1 + -0.5 \cdot \frac{{\ell}^{2} \cdot {ky}^{2}}{{Om}^{2}}} \]
    11. Step-by-step derivation
      1. *-commutative24.1%

        \[\leadsto 1 + \color{blue}{\frac{{\ell}^{2} \cdot {ky}^{2}}{{Om}^{2}} \cdot -0.5} \]
      2. associate-/l*24.1%

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

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

        \[\leadsto 1 + \frac{\ell \cdot \ell}{\frac{\color{blue}{Om \cdot Om}}{{ky}^{2}}} \cdot -0.5 \]
      5. unpow224.1%

        \[\leadsto 1 + \frac{\ell \cdot \ell}{\frac{Om \cdot Om}{\color{blue}{ky \cdot ky}}} \cdot -0.5 \]
    12. Simplified24.1%

      \[\leadsto \color{blue}{1 + \frac{\ell \cdot \ell}{\frac{Om \cdot Om}{ky \cdot ky}} \cdot -0.5} \]
    13. Step-by-step derivation
      1. *-un-lft-identity24.1%

        \[\leadsto 1 + \frac{\color{blue}{1 \cdot \left(\ell \cdot \ell\right)}}{\frac{Om \cdot Om}{ky \cdot ky}} \cdot -0.5 \]
      2. add-sqr-sqrt24.1%

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

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

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

        \[\leadsto 1 + \left(\frac{1}{\color{blue}{\sqrt{\frac{Om}{ky}} \cdot \sqrt{\frac{Om}{ky}}}} \cdot \frac{\ell \cdot \ell}{\sqrt{\frac{Om \cdot Om}{ky \cdot ky}}}\right) \cdot -0.5 \]
      6. add-sqr-sqrt24.8%

        \[\leadsto 1 + \left(\frac{1}{\color{blue}{\frac{Om}{ky}}} \cdot \frac{\ell \cdot \ell}{\sqrt{\frac{Om \cdot Om}{ky \cdot ky}}}\right) \cdot -0.5 \]
      7. times-frac30.7%

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

        \[\leadsto 1 + \left(\frac{1}{\frac{Om}{ky}} \cdot \frac{\ell \cdot \ell}{\color{blue}{\sqrt{\frac{Om}{ky}} \cdot \sqrt{\frac{Om}{ky}}}}\right) \cdot -0.5 \]
      9. add-sqr-sqrt33.2%

        \[\leadsto 1 + \left(\frac{1}{\frac{Om}{ky}} \cdot \frac{\ell \cdot \ell}{\color{blue}{\frac{Om}{ky}}}\right) \cdot -0.5 \]
    14. Applied egg-rr33.2%

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

    if 2.00000000000000007e121 < Om

    1. Initial program 99.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. Simplified99.9%

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

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

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

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

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

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

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

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

      \[\leadsto \sqrt{0.5 + 0.5 \cdot \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}}} \]
    8. Step-by-step derivation
      1. expm1-def99.9%

        \[\leadsto \sqrt{0.5 + 0.5 \cdot \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)}}} \]
      2. expm1-log1p99.9%

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

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

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

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

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

      \[\leadsto \color{blue}{1 + -0.5 \cdot \frac{{\ell}^{2} \cdot {ky}^{2}}{{Om}^{2}}} \]
    11. Step-by-step derivation
      1. *-commutative60.0%

        \[\leadsto 1 + \color{blue}{\frac{{\ell}^{2} \cdot {ky}^{2}}{{Om}^{2}} \cdot -0.5} \]
      2. associate-/l*63.3%

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

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

        \[\leadsto 1 + \frac{\ell \cdot \ell}{\frac{\color{blue}{Om \cdot Om}}{{ky}^{2}}} \cdot -0.5 \]
      5. unpow263.3%

        \[\leadsto 1 + \frac{\ell \cdot \ell}{\frac{Om \cdot Om}{\color{blue}{ky \cdot ky}}} \cdot -0.5 \]
    12. Simplified63.3%

      \[\leadsto \color{blue}{1 + \frac{\ell \cdot \ell}{\frac{Om \cdot Om}{ky \cdot ky}} \cdot -0.5} \]
    13. Step-by-step derivation
      1. associate-/r*90.0%

        \[\leadsto 1 + \frac{\ell \cdot \ell}{\color{blue}{\frac{\frac{Om \cdot Om}{ky}}{ky}}} \cdot -0.5 \]
      2. div-inv90.0%

        \[\leadsto 1 + \frac{\ell \cdot \ell}{\color{blue}{\frac{Om \cdot Om}{ky} \cdot \frac{1}{ky}}} \cdot -0.5 \]
    14. Applied egg-rr90.0%

      \[\leadsto 1 + \frac{\ell \cdot \ell}{\color{blue}{\frac{Om \cdot Om}{ky} \cdot \frac{1}{ky}}} \cdot -0.5 \]
  3. Recombined 2 regimes into one program.
  4. Final simplification39.9%

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

Alternative 6: 35.0% accurate, 48.1× speedup?

\[\begin{array}{l} kx = |kx|\\ ky = |ky|\\ [kx, ky] = \mathsf{sort}([kx, ky])\\ \\ 1 + -0.5 \cdot \left(\ell \cdot \left(\ell \cdot \left(\frac{ky}{Om} \cdot \frac{ky}{Om}\right)\right)\right) \end{array} \]
NOTE: kx should be positive before calling this function
NOTE: ky should be positive before calling this function
NOTE: kx and ky should be sorted in increasing order before calling this function.
(FPCore (l Om kx ky)
 :precision binary64
 (+ 1.0 (* -0.5 (* l (* l (* (/ ky Om) (/ ky Om)))))))
kx = abs(kx);
ky = abs(ky);
assert(kx < ky);
double code(double l, double Om, double kx, double ky) {
	return 1.0 + (-0.5 * (l * (l * ((ky / Om) * (ky / Om)))));
}
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 = 1.0d0 + ((-0.5d0) * (l * (l * ((ky / om) * (ky / om)))))
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 1.0 + (-0.5 * (l * (l * ((ky / Om) * (ky / Om)))));
}
kx = abs(kx)
ky = abs(ky)
[kx, ky] = sort([kx, ky])
def code(l, Om, kx, ky):
	return 1.0 + (-0.5 * (l * (l * ((ky / Om) * (ky / Om)))))
kx = abs(kx)
ky = abs(ky)
kx, ky = sort([kx, ky])
function code(l, Om, kx, ky)
	return Float64(1.0 + Float64(-0.5 * Float64(l * Float64(l * Float64(Float64(ky / Om) * Float64(ky / Om))))))
end
kx = abs(kx)
ky = abs(ky)
kx, ky = num2cell(sort([kx, ky])){:}
function tmp = code(l, Om, kx, ky)
	tmp = 1.0 + (-0.5 * (l * (l * ((ky / Om) * (ky / 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[(1.0 + N[(-0.5 * N[(l * N[(l * N[(N[(ky / Om), $MachinePrecision] * N[(ky / Om), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
kx = |kx|\\
ky = |ky|\\
[kx, ky] = \mathsf{sort}([kx, ky])\\
\\
1 + -0.5 \cdot \left(\ell \cdot \left(\ell \cdot \left(\frac{ky}{Om} \cdot \frac{ky}{Om}\right)\right)\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. Simplified99.2%

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

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

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

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

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

    \[\leadsto \sqrt{0.5 + 0.5 \cdot \frac{1}{\color{blue}{\sqrt{1 + 4 \cdot \frac{\ell \cdot \ell}{\frac{Om \cdot Om}{{\sin ky}^{2}}}}}}} \]
  6. Step-by-step derivation
    1. expm1-log1p-u79.2%

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

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

    \[\leadsto \sqrt{0.5 + 0.5 \cdot \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}}} \]
  8. Step-by-step derivation
    1. expm1-def92.4%

      \[\leadsto \sqrt{0.5 + 0.5 \cdot \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)}}} \]
    2. expm1-log1p92.4%

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

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

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

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

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

    \[\leadsto \color{blue}{1 + -0.5 \cdot \frac{{\ell}^{2} \cdot {ky}^{2}}{{Om}^{2}}} \]
  11. Step-by-step derivation
    1. *-commutative28.3%

      \[\leadsto 1 + \color{blue}{\frac{{\ell}^{2} \cdot {ky}^{2}}{{Om}^{2}} \cdot -0.5} \]
    2. associate-/l*28.7%

      \[\leadsto 1 + \color{blue}{\frac{{\ell}^{2}}{\frac{{Om}^{2}}{{ky}^{2}}}} \cdot -0.5 \]
    3. unpow228.7%

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

      \[\leadsto 1 + \frac{\ell \cdot \ell}{\frac{\color{blue}{Om \cdot Om}}{{ky}^{2}}} \cdot -0.5 \]
    5. unpow228.7%

      \[\leadsto 1 + \frac{\ell \cdot \ell}{\frac{Om \cdot Om}{\color{blue}{ky \cdot ky}}} \cdot -0.5 \]
  12. Simplified28.7%

    \[\leadsto \color{blue}{1 + \frac{\ell \cdot \ell}{\frac{Om \cdot Om}{ky \cdot ky}} \cdot -0.5} \]
  13. Step-by-step derivation
    1. div-inv28.3%

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

      \[\leadsto 1 + \left(\left(\ell \cdot \ell\right) \cdot \color{blue}{\frac{ky \cdot ky}{Om \cdot Om}}\right) \cdot -0.5 \]
    3. associate-*l*31.1%

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

      \[\leadsto 1 + \left(\ell \cdot \left(\ell \cdot \color{blue}{\left(\frac{ky}{Om} \cdot \frac{ky}{Om}\right)}\right)\right) \cdot -0.5 \]
  14. Applied egg-rr37.6%

    \[\leadsto 1 + \color{blue}{\left(\ell \cdot \left(\ell \cdot \left(\frac{ky}{Om} \cdot \frac{ky}{Om}\right)\right)\right)} \cdot -0.5 \]
  15. Final simplification37.6%

    \[\leadsto 1 + -0.5 \cdot \left(\ell \cdot \left(\ell \cdot \left(\frac{ky}{Om} \cdot \frac{ky}{Om}\right)\right)\right) \]

Alternative 7: 37.4% accurate, 48.1× speedup?

\[\begin{array}{l} kx = |kx|\\ ky = |ky|\\ [kx, ky] = \mathsf{sort}([kx, ky])\\ \\ \begin{array}{l} t_0 := \frac{\ell}{Om} \cdot ky\\ 1 + -0.5 \cdot \left(t_0 \cdot t_0\right) \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
 (let* ((t_0 (* (/ l Om) ky))) (+ 1.0 (* -0.5 (* t_0 t_0)))))
kx = abs(kx);
ky = abs(ky);
assert(kx < ky);
double code(double l, double Om, double kx, double ky) {
	double t_0 = (l / Om) * ky;
	return 1.0 + (-0.5 * (t_0 * t_0));
}
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) :: t_0
    t_0 = (l / om) * ky
    code = 1.0d0 + ((-0.5d0) * (t_0 * t_0))
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 t_0 = (l / Om) * ky;
	return 1.0 + (-0.5 * (t_0 * t_0));
}
kx = abs(kx)
ky = abs(ky)
[kx, ky] = sort([kx, ky])
def code(l, Om, kx, ky):
	t_0 = (l / Om) * ky
	return 1.0 + (-0.5 * (t_0 * t_0))
kx = abs(kx)
ky = abs(ky)
kx, ky = sort([kx, ky])
function code(l, Om, kx, ky)
	t_0 = Float64(Float64(l / Om) * ky)
	return Float64(1.0 + Float64(-0.5 * Float64(t_0 * t_0)))
end
kx = abs(kx)
ky = abs(ky)
kx, ky = num2cell(sort([kx, ky])){:}
function tmp = code(l, Om, kx, ky)
	t_0 = (l / Om) * ky;
	tmp = 1.0 + (-0.5 * (t_0 * t_0));
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_] := Block[{t$95$0 = N[(N[(l / Om), $MachinePrecision] * ky), $MachinePrecision]}, N[(1.0 + N[(-0.5 * N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
kx = |kx|\\
ky = |ky|\\
[kx, ky] = \mathsf{sort}([kx, ky])\\
\\
\begin{array}{l}
t_0 := \frac{\ell}{Om} \cdot ky\\
1 + -0.5 \cdot \left(t_0 \cdot t_0\right)
\end{array}
\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. Simplified99.2%

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

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

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

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

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

    \[\leadsto \sqrt{0.5 + 0.5 \cdot \frac{1}{\color{blue}{\sqrt{1 + 4 \cdot \frac{\ell \cdot \ell}{\frac{Om \cdot Om}{{\sin ky}^{2}}}}}}} \]
  6. Step-by-step derivation
    1. expm1-log1p-u79.2%

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

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

    \[\leadsto \sqrt{0.5 + 0.5 \cdot \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}}} \]
  8. Step-by-step derivation
    1. expm1-def92.4%

      \[\leadsto \sqrt{0.5 + 0.5 \cdot \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)}}} \]
    2. expm1-log1p92.4%

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

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

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

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

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

    \[\leadsto \color{blue}{1 + -0.5 \cdot \frac{{\ell}^{2} \cdot {ky}^{2}}{{Om}^{2}}} \]
  11. Step-by-step derivation
    1. *-commutative28.3%

      \[\leadsto 1 + \color{blue}{\frac{{\ell}^{2} \cdot {ky}^{2}}{{Om}^{2}} \cdot -0.5} \]
    2. associate-/l*28.7%

      \[\leadsto 1 + \color{blue}{\frac{{\ell}^{2}}{\frac{{Om}^{2}}{{ky}^{2}}}} \cdot -0.5 \]
    3. unpow228.7%

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

      \[\leadsto 1 + \frac{\ell \cdot \ell}{\frac{\color{blue}{Om \cdot Om}}{{ky}^{2}}} \cdot -0.5 \]
    5. unpow228.7%

      \[\leadsto 1 + \frac{\ell \cdot \ell}{\frac{Om \cdot Om}{\color{blue}{ky \cdot ky}}} \cdot -0.5 \]
  12. Simplified28.7%

    \[\leadsto \color{blue}{1 + \frac{\ell \cdot \ell}{\frac{Om \cdot Om}{ky \cdot ky}} \cdot -0.5} \]
  13. Step-by-step derivation
    1. add-sqr-sqrt28.7%

      \[\leadsto 1 + \color{blue}{\left(\sqrt{\frac{\ell \cdot \ell}{\frac{Om \cdot Om}{ky \cdot ky}}} \cdot \sqrt{\frac{\ell \cdot \ell}{\frac{Om \cdot Om}{ky \cdot ky}}}\right)} \cdot -0.5 \]
    2. associate-/r/28.6%

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

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

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

      \[\leadsto 1 + \left(\left(\color{blue}{\left(\sqrt{\frac{\ell}{Om}} \cdot \sqrt{\frac{\ell}{Om}}\right)} \cdot \sqrt{ky \cdot ky}\right) \cdot \sqrt{\frac{\ell \cdot \ell}{\frac{Om \cdot Om}{ky \cdot ky}}}\right) \cdot -0.5 \]
    6. add-sqr-sqrt29.1%

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

      \[\leadsto 1 + \left(\left(\frac{\ell}{Om} \cdot \color{blue}{\left(\sqrt{ky} \cdot \sqrt{ky}\right)}\right) \cdot \sqrt{\frac{\ell \cdot \ell}{\frac{Om \cdot Om}{ky \cdot ky}}}\right) \cdot -0.5 \]
    8. add-sqr-sqrt29.3%

      \[\leadsto 1 + \left(\left(\frac{\ell}{Om} \cdot \color{blue}{ky}\right) \cdot \sqrt{\frac{\ell \cdot \ell}{\frac{Om \cdot Om}{ky \cdot ky}}}\right) \cdot -0.5 \]
    9. associate-/r/30.0%

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

      \[\leadsto 1 + \left(\left(\frac{\ell}{Om} \cdot ky\right) \cdot \color{blue}{\left(\sqrt{\frac{\ell \cdot \ell}{Om \cdot Om}} \cdot \sqrt{ky \cdot ky}\right)}\right) \cdot -0.5 \]
    11. frac-times33.0%

      \[\leadsto 1 + \left(\left(\frac{\ell}{Om} \cdot ky\right) \cdot \left(\sqrt{\color{blue}{\frac{\ell}{Om} \cdot \frac{\ell}{Om}}} \cdot \sqrt{ky \cdot ky}\right)\right) \cdot -0.5 \]
    12. sqrt-unprod22.7%

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

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

      \[\leadsto 1 + \left(\left(\frac{\ell}{Om} \cdot ky\right) \cdot \left(\frac{\ell}{Om} \cdot \color{blue}{\left(\sqrt{ky} \cdot \sqrt{ky}\right)}\right)\right) \cdot -0.5 \]
    15. add-sqr-sqrt39.1%

      \[\leadsto 1 + \left(\left(\frac{\ell}{Om} \cdot ky\right) \cdot \left(\frac{\ell}{Om} \cdot \color{blue}{ky}\right)\right) \cdot -0.5 \]
  14. Applied egg-rr39.1%

    \[\leadsto 1 + \color{blue}{\left(\left(\frac{\ell}{Om} \cdot ky\right) \cdot \left(\frac{\ell}{Om} \cdot ky\right)\right)} \cdot -0.5 \]
  15. Final simplification39.1%

    \[\leadsto 1 + -0.5 \cdot \left(\left(\frac{\ell}{Om} \cdot ky\right) \cdot \left(\frac{\ell}{Om} \cdot ky\right)\right) \]

Alternative 8: 38.2% accurate, 48.1× speedup?

\[\begin{array}{l} kx = |kx|\\ ky = |ky|\\ [kx, ky] = \mathsf{sort}([kx, ky])\\ \\ 1 + -0.5 \cdot \frac{ky \cdot \frac{\ell \cdot \ell}{Om}}{\frac{Om}{ky}} \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
 (+ 1.0 (* -0.5 (/ (* ky (/ (* l l) Om)) (/ Om ky)))))
kx = abs(kx);
ky = abs(ky);
assert(kx < ky);
double code(double l, double Om, double kx, double ky) {
	return 1.0 + (-0.5 * ((ky * ((l * l) / Om)) / (Om / ky)));
}
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 = 1.0d0 + ((-0.5d0) * ((ky * ((l * l) / om)) / (om / ky)))
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 1.0 + (-0.5 * ((ky * ((l * l) / Om)) / (Om / ky)));
}
kx = abs(kx)
ky = abs(ky)
[kx, ky] = sort([kx, ky])
def code(l, Om, kx, ky):
	return 1.0 + (-0.5 * ((ky * ((l * l) / Om)) / (Om / ky)))
kx = abs(kx)
ky = abs(ky)
kx, ky = sort([kx, ky])
function code(l, Om, kx, ky)
	return Float64(1.0 + Float64(-0.5 * Float64(Float64(ky * Float64(Float64(l * l) / Om)) / Float64(Om / ky))))
end
kx = abs(kx)
ky = abs(ky)
kx, ky = num2cell(sort([kx, ky])){:}
function tmp = code(l, Om, kx, ky)
	tmp = 1.0 + (-0.5 * ((ky * ((l * l) / Om)) / (Om / ky)));
end
NOTE: kx should be positive before calling this function
NOTE: ky should be positive before calling this function
NOTE: kx and ky should be sorted in increasing order before calling this function.
code[l_, Om_, kx_, ky_] := N[(1.0 + N[(-0.5 * N[(N[(ky * N[(N[(l * l), $MachinePrecision] / Om), $MachinePrecision]), $MachinePrecision] / N[(Om / ky), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
kx = |kx|\\
ky = |ky|\\
[kx, ky] = \mathsf{sort}([kx, ky])\\
\\
1 + -0.5 \cdot \frac{ky \cdot \frac{\ell \cdot \ell}{Om}}{\frac{Om}{ky}}
\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. Simplified99.2%

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

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

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

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

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

    \[\leadsto \sqrt{0.5 + 0.5 \cdot \frac{1}{\color{blue}{\sqrt{1 + 4 \cdot \frac{\ell \cdot \ell}{\frac{Om \cdot Om}{{\sin ky}^{2}}}}}}} \]
  6. Step-by-step derivation
    1. expm1-log1p-u79.2%

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

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

    \[\leadsto \sqrt{0.5 + 0.5 \cdot \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}}} \]
  8. Step-by-step derivation
    1. expm1-def92.4%

      \[\leadsto \sqrt{0.5 + 0.5 \cdot \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)}}} \]
    2. expm1-log1p92.4%

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

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

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

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

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

    \[\leadsto \color{blue}{1 + -0.5 \cdot \frac{{\ell}^{2} \cdot {ky}^{2}}{{Om}^{2}}} \]
  11. Step-by-step derivation
    1. *-commutative28.3%

      \[\leadsto 1 + \color{blue}{\frac{{\ell}^{2} \cdot {ky}^{2}}{{Om}^{2}} \cdot -0.5} \]
    2. associate-/l*28.7%

      \[\leadsto 1 + \color{blue}{\frac{{\ell}^{2}}{\frac{{Om}^{2}}{{ky}^{2}}}} \cdot -0.5 \]
    3. unpow228.7%

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

      \[\leadsto 1 + \frac{\ell \cdot \ell}{\frac{\color{blue}{Om \cdot Om}}{{ky}^{2}}} \cdot -0.5 \]
    5. unpow228.7%

      \[\leadsto 1 + \frac{\ell \cdot \ell}{\frac{Om \cdot Om}{\color{blue}{ky \cdot ky}}} \cdot -0.5 \]
  12. Simplified28.7%

    \[\leadsto \color{blue}{1 + \frac{\ell \cdot \ell}{\frac{Om \cdot Om}{ky \cdot ky}} \cdot -0.5} \]
  13. Step-by-step derivation
    1. *-un-lft-identity28.7%

      \[\leadsto 1 + \frac{\color{blue}{1 \cdot \left(\ell \cdot \ell\right)}}{\frac{Om \cdot Om}{ky \cdot ky}} \cdot -0.5 \]
    2. add-sqr-sqrt28.7%

      \[\leadsto 1 + \frac{1 \cdot \left(\ell \cdot \ell\right)}{\color{blue}{\sqrt{\frac{Om \cdot Om}{ky \cdot ky}} \cdot \sqrt{\frac{Om \cdot Om}{ky \cdot ky}}}} \cdot -0.5 \]
    3. times-frac28.7%

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

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

      \[\leadsto 1 + \left(\frac{1}{\color{blue}{\sqrt{\frac{Om}{ky}} \cdot \sqrt{\frac{Om}{ky}}}} \cdot \frac{\ell \cdot \ell}{\sqrt{\frac{Om \cdot Om}{ky \cdot ky}}}\right) \cdot -0.5 \]
    6. add-sqr-sqrt29.3%

      \[\leadsto 1 + \left(\frac{1}{\color{blue}{\frac{Om}{ky}}} \cdot \frac{\ell \cdot \ell}{\sqrt{\frac{Om \cdot Om}{ky \cdot ky}}}\right) \cdot -0.5 \]
    7. times-frac36.5%

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

      \[\leadsto 1 + \left(\frac{1}{\frac{Om}{ky}} \cdot \frac{\ell \cdot \ell}{\color{blue}{\sqrt{\frac{Om}{ky}} \cdot \sqrt{\frac{Om}{ky}}}}\right) \cdot -0.5 \]
    9. add-sqr-sqrt38.7%

      \[\leadsto 1 + \left(\frac{1}{\frac{Om}{ky}} \cdot \frac{\ell \cdot \ell}{\color{blue}{\frac{Om}{ky}}}\right) \cdot -0.5 \]
  14. Applied egg-rr38.7%

    \[\leadsto 1 + \color{blue}{\left(\frac{1}{\frac{Om}{ky}} \cdot \frac{\ell \cdot \ell}{\frac{Om}{ky}}\right)} \cdot -0.5 \]
  15. Step-by-step derivation
    1. associate-*l/38.7%

      \[\leadsto 1 + \color{blue}{\frac{1 \cdot \frac{\ell \cdot \ell}{\frac{Om}{ky}}}{\frac{Om}{ky}}} \cdot -0.5 \]
    2. *-lft-identity38.7%

      \[\leadsto 1 + \frac{\color{blue}{\frac{\ell \cdot \ell}{\frac{Om}{ky}}}}{\frac{Om}{ky}} \cdot -0.5 \]
    3. unpow238.7%

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

      \[\leadsto 1 + \frac{\color{blue}{\frac{{\ell}^{2}}{Om} \cdot ky}}{\frac{Om}{ky}} \cdot -0.5 \]
    5. unpow238.6%

      \[\leadsto 1 + \frac{\frac{\color{blue}{\ell \cdot \ell}}{Om} \cdot ky}{\frac{Om}{ky}} \cdot -0.5 \]
  16. Simplified38.6%

    \[\leadsto 1 + \color{blue}{\frac{\frac{\ell \cdot \ell}{Om} \cdot ky}{\frac{Om}{ky}}} \cdot -0.5 \]
  17. Final simplification38.6%

    \[\leadsto 1 + -0.5 \cdot \frac{ky \cdot \frac{\ell \cdot \ell}{Om}}{\frac{Om}{ky}} \]

Reproduce

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