Toniolo and Linder, Equation (3a)

Percentage Accurate: 98.5% → 100.0%
Time: 16.1s
Alternatives: 8
Speedup: 1.4×

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.5% 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: 100.0% accurate, 1.4× speedup?

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

\\
\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, \mathsf{hypot}\left(\sin ky, \sin kx\right) \cdot \left(2 \cdot \frac{\ell}{Om}\right)\right)}}
\end{array}
Derivation
  1. Initial program 97.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. Simplified97.7%

    \[\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. Step-by-step derivation
    1. expm1-log1p-u97.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 87.4% accurate, 2.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 8.2 \cdot 10^{+94}:\\ \;\;\;\;\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, 2 \cdot \frac{ky \cdot \ell}{Om}\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, \sin kx \cdot \left(2 \cdot \frac{\ell}{Om}\right)\right)}}\\ \end{array} \end{array} \]
(FPCore (l Om kx ky)
 :precision binary64
 (if (<= ky 8.2e+94)
   (sqrt (+ 0.5 (/ 0.5 (hypot 1.0 (* 2.0 (/ (* ky l) Om))))))
   (sqrt (+ 0.5 (/ 0.5 (hypot 1.0 (* (sin kx) (* 2.0 (/ l Om)))))))))
double code(double l, double Om, double kx, double ky) {
	double tmp;
	if (ky <= 8.2e+94) {
		tmp = sqrt((0.5 + (0.5 / hypot(1.0, (2.0 * ((ky * l) / Om))))));
	} else {
		tmp = sqrt((0.5 + (0.5 / hypot(1.0, (sin(kx) * (2.0 * (l / Om)))))));
	}
	return tmp;
}
public static double code(double l, double Om, double kx, double ky) {
	double tmp;
	if (ky <= 8.2e+94) {
		tmp = Math.sqrt((0.5 + (0.5 / Math.hypot(1.0, (2.0 * ((ky * l) / Om))))));
	} else {
		tmp = Math.sqrt((0.5 + (0.5 / Math.hypot(1.0, (Math.sin(kx) * (2.0 * (l / Om)))))));
	}
	return tmp;
}
def code(l, Om, kx, ky):
	tmp = 0
	if ky <= 8.2e+94:
		tmp = math.sqrt((0.5 + (0.5 / math.hypot(1.0, (2.0 * ((ky * l) / Om))))))
	else:
		tmp = math.sqrt((0.5 + (0.5 / math.hypot(1.0, (math.sin(kx) * (2.0 * (l / Om)))))))
	return tmp
function code(l, Om, kx, ky)
	tmp = 0.0
	if (ky <= 8.2e+94)
		tmp = sqrt(Float64(0.5 + Float64(0.5 / hypot(1.0, Float64(2.0 * Float64(Float64(ky * l) / Om))))));
	else
		tmp = sqrt(Float64(0.5 + Float64(0.5 / hypot(1.0, Float64(sin(kx) * Float64(2.0 * Float64(l / Om)))))));
	end
	return tmp
end
function tmp_2 = code(l, Om, kx, ky)
	tmp = 0.0;
	if (ky <= 8.2e+94)
		tmp = sqrt((0.5 + (0.5 / hypot(1.0, (2.0 * ((ky * l) / Om))))));
	else
		tmp = sqrt((0.5 + (0.5 / hypot(1.0, (sin(kx) * (2.0 * (l / Om)))))));
	end
	tmp_2 = tmp;
end
code[l_, Om_, kx_, ky_] := If[LessEqual[ky, 8.2e+94], N[Sqrt[N[(0.5 + N[(0.5 / N[Sqrt[1.0 ^ 2 + N[(2.0 * N[(N[(ky * l), $MachinePrecision] / Om), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[N[(0.5 + N[(0.5 / N[Sqrt[1.0 ^ 2 + N[(N[Sin[kx], $MachinePrecision] * N[(2.0 * N[(l / Om), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq 8.2 \cdot 10^{+94}:\\
\;\;\;\;\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, 2 \cdot \frac{ky \cdot \ell}{Om}\right)}}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, \sin kx \cdot \left(2 \cdot \frac{\ell}{Om}\right)\right)}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < 8.20000000000000061e94

    1. Initial program 97.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. Simplified97.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. Step-by-step derivation
      1. expm1-log1p-u97.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 8.20000000000000061e94 < ky

    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. Step-by-step derivation
      1. expm1-log1p-u100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, \color{blue}{2 \cdot \frac{\ell \cdot \sin kx}{Om}}\right)}} \]
    12. Step-by-step derivation
      1. *-commutative92.1%

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

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

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

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

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

      \[\leadsto \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, \color{blue}{\sin kx \cdot \left(2 \cdot \frac{\ell}{Om}\right)}\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification87.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq 8.2 \cdot 10^{+94}:\\ \;\;\;\;\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, 2 \cdot \frac{ky \cdot \ell}{Om}\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, \sin kx \cdot \left(2 \cdot \frac{\ell}{Om}\right)\right)}}\\ \end{array} \]

Alternative 3: 93.7% accurate, 2.3× speedup?

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

\\
\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, \sin ky \cdot \left(2 \cdot \frac{\ell}{Om}\right)\right)}}
\end{array}
Derivation
  1. Initial program 97.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. Simplified97.7%

    \[\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. Step-by-step derivation
    1. expm1-log1p-u97.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 73.5% accurate, 3.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq 6.6 \cdot 10^{-62}:\\ \;\;\;\;1\\ \mathbf{elif}\;\ell \leq 10^{+24}:\\ \;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{1}{1 + 2 \cdot \frac{ky \cdot \ell}{\frac{Om}{\ell} \cdot \frac{Om}{ky}}}}\\ \mathbf{elif}\;\ell \leq 2.5 \cdot 10^{+34}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, 2 \cdot \frac{ky \cdot \ell}{Om}\right)}}\\ \end{array} \end{array} \]
(FPCore (l Om kx ky)
 :precision binary64
 (if (<= l 6.6e-62)
   1.0
   (if (<= l 1e+24)
     (sqrt
      (+
       0.5
       (* 0.5 (/ 1.0 (+ 1.0 (* 2.0 (/ (* ky l) (* (/ Om l) (/ Om ky)))))))))
     (if (<= l 2.5e+34)
       1.0
       (sqrt (+ 0.5 (/ 0.5 (hypot 1.0 (* 2.0 (/ (* ky l) Om))))))))))
double code(double l, double Om, double kx, double ky) {
	double tmp;
	if (l <= 6.6e-62) {
		tmp = 1.0;
	} else if (l <= 1e+24) {
		tmp = sqrt((0.5 + (0.5 * (1.0 / (1.0 + (2.0 * ((ky * l) / ((Om / l) * (Om / ky)))))))));
	} else if (l <= 2.5e+34) {
		tmp = 1.0;
	} else {
		tmp = sqrt((0.5 + (0.5 / hypot(1.0, (2.0 * ((ky * l) / Om))))));
	}
	return tmp;
}
public static double code(double l, double Om, double kx, double ky) {
	double tmp;
	if (l <= 6.6e-62) {
		tmp = 1.0;
	} else if (l <= 1e+24) {
		tmp = Math.sqrt((0.5 + (0.5 * (1.0 / (1.0 + (2.0 * ((ky * l) / ((Om / l) * (Om / ky)))))))));
	} else if (l <= 2.5e+34) {
		tmp = 1.0;
	} else {
		tmp = Math.sqrt((0.5 + (0.5 / Math.hypot(1.0, (2.0 * ((ky * l) / Om))))));
	}
	return tmp;
}
def code(l, Om, kx, ky):
	tmp = 0
	if l <= 6.6e-62:
		tmp = 1.0
	elif l <= 1e+24:
		tmp = math.sqrt((0.5 + (0.5 * (1.0 / (1.0 + (2.0 * ((ky * l) / ((Om / l) * (Om / ky)))))))))
	elif l <= 2.5e+34:
		tmp = 1.0
	else:
		tmp = math.sqrt((0.5 + (0.5 / math.hypot(1.0, (2.0 * ((ky * l) / Om))))))
	return tmp
function code(l, Om, kx, ky)
	tmp = 0.0
	if (l <= 6.6e-62)
		tmp = 1.0;
	elseif (l <= 1e+24)
		tmp = sqrt(Float64(0.5 + Float64(0.5 * Float64(1.0 / Float64(1.0 + Float64(2.0 * Float64(Float64(ky * l) / Float64(Float64(Om / l) * Float64(Om / ky)))))))));
	elseif (l <= 2.5e+34)
		tmp = 1.0;
	else
		tmp = sqrt(Float64(0.5 + Float64(0.5 / hypot(1.0, Float64(2.0 * Float64(Float64(ky * l) / Om))))));
	end
	return tmp
end
function tmp_2 = code(l, Om, kx, ky)
	tmp = 0.0;
	if (l <= 6.6e-62)
		tmp = 1.0;
	elseif (l <= 1e+24)
		tmp = sqrt((0.5 + (0.5 * (1.0 / (1.0 + (2.0 * ((ky * l) / ((Om / l) * (Om / ky)))))))));
	elseif (l <= 2.5e+34)
		tmp = 1.0;
	else
		tmp = sqrt((0.5 + (0.5 / hypot(1.0, (2.0 * ((ky * l) / Om))))));
	end
	tmp_2 = tmp;
end
code[l_, Om_, kx_, ky_] := If[LessEqual[l, 6.6e-62], 1.0, If[LessEqual[l, 1e+24], N[Sqrt[N[(0.5 + N[(0.5 * N[(1.0 / N[(1.0 + N[(2.0 * N[(N[(ky * l), $MachinePrecision] / N[(N[(Om / l), $MachinePrecision] * N[(Om / ky), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[l, 2.5e+34], 1.0, N[Sqrt[N[(0.5 + N[(0.5 / N[Sqrt[1.0 ^ 2 + N[(2.0 * N[(N[(ky * l), $MachinePrecision] / Om), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 6.6 \cdot 10^{-62}:\\
\;\;\;\;1\\

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

\mathbf{elif}\;\ell \leq 2.5 \cdot 10^{+34}:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, 2 \cdot \frac{ky \cdot \ell}{Om}\right)}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < 6.60000000000000009e-62 or 9.9999999999999998e23 < l < 2.4999999999999999e34

    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. Step-by-step derivation
      1. expm1-log1p-u99.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 6.60000000000000009e-62 < l < 9.9999999999999998e23

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{0.5 + 0.5 \cdot \frac{1}{1 + 2 \cdot \color{blue}{\frac{\ell \cdot ky}{\frac{Om}{\ell} \cdot \frac{Om}{ky}}}}} \]
    10. Applied egg-rr100.0%

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

    if 2.4999999999999999e34 < l

    1. Initial program 92.3%

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

      \[\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. Step-by-step derivation
      1. expm1-log1p-u92.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 6.6 \cdot 10^{-62}:\\ \;\;\;\;1\\ \mathbf{elif}\;\ell \leq 10^{+24}:\\ \;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{1}{1 + 2 \cdot \frac{ky \cdot \ell}{\frac{Om}{\ell} \cdot \frac{Om}{ky}}}}\\ \mathbf{elif}\;\ell \leq 2.5 \cdot 10^{+34}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, 2 \cdot \frac{ky \cdot \ell}{Om}\right)}}\\ \end{array} \]

Alternative 5: 73.5% accurate, 5.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq 1.1 \cdot 10^{-61}:\\ \;\;\;\;1\\ \mathbf{elif}\;\ell \leq 1.3 \cdot 10^{+24} \lor \neg \left(\ell \leq 4 \cdot 10^{+34}\right):\\ \;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{1}{1 + 2 \cdot \frac{ky \cdot \ell}{\frac{Om}{\ell} \cdot \frac{Om}{ky}}}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
(FPCore (l Om kx ky)
 :precision binary64
 (if (<= l 1.1e-61)
   1.0
   (if (or (<= l 1.3e+24) (not (<= l 4e+34)))
     (sqrt
      (+
       0.5
       (* 0.5 (/ 1.0 (+ 1.0 (* 2.0 (/ (* ky l) (* (/ Om l) (/ Om ky)))))))))
     1.0)))
double code(double l, double Om, double kx, double ky) {
	double tmp;
	if (l <= 1.1e-61) {
		tmp = 1.0;
	} else if ((l <= 1.3e+24) || !(l <= 4e+34)) {
		tmp = sqrt((0.5 + (0.5 * (1.0 / (1.0 + (2.0 * ((ky * l) / ((Om / l) * (Om / ky)))))))));
	} else {
		tmp = 1.0;
	}
	return tmp;
}
real(8) function code(l, om, kx, ky)
    real(8), intent (in) :: l
    real(8), intent (in) :: om
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8) :: tmp
    if (l <= 1.1d-61) then
        tmp = 1.0d0
    else if ((l <= 1.3d+24) .or. (.not. (l <= 4d+34))) then
        tmp = sqrt((0.5d0 + (0.5d0 * (1.0d0 / (1.0d0 + (2.0d0 * ((ky * l) / ((om / l) * (om / ky)))))))))
    else
        tmp = 1.0d0
    end if
    code = tmp
end function
public static double code(double l, double Om, double kx, double ky) {
	double tmp;
	if (l <= 1.1e-61) {
		tmp = 1.0;
	} else if ((l <= 1.3e+24) || !(l <= 4e+34)) {
		tmp = Math.sqrt((0.5 + (0.5 * (1.0 / (1.0 + (2.0 * ((ky * l) / ((Om / l) * (Om / ky)))))))));
	} else {
		tmp = 1.0;
	}
	return tmp;
}
def code(l, Om, kx, ky):
	tmp = 0
	if l <= 1.1e-61:
		tmp = 1.0
	elif (l <= 1.3e+24) or not (l <= 4e+34):
		tmp = math.sqrt((0.5 + (0.5 * (1.0 / (1.0 + (2.0 * ((ky * l) / ((Om / l) * (Om / ky)))))))))
	else:
		tmp = 1.0
	return tmp
function code(l, Om, kx, ky)
	tmp = 0.0
	if (l <= 1.1e-61)
		tmp = 1.0;
	elseif ((l <= 1.3e+24) || !(l <= 4e+34))
		tmp = sqrt(Float64(0.5 + Float64(0.5 * Float64(1.0 / Float64(1.0 + Float64(2.0 * Float64(Float64(ky * l) / Float64(Float64(Om / l) * Float64(Om / ky)))))))));
	else
		tmp = 1.0;
	end
	return tmp
end
function tmp_2 = code(l, Om, kx, ky)
	tmp = 0.0;
	if (l <= 1.1e-61)
		tmp = 1.0;
	elseif ((l <= 1.3e+24) || ~((l <= 4e+34)))
		tmp = sqrt((0.5 + (0.5 * (1.0 / (1.0 + (2.0 * ((ky * l) / ((Om / l) * (Om / ky)))))))));
	else
		tmp = 1.0;
	end
	tmp_2 = tmp;
end
code[l_, Om_, kx_, ky_] := If[LessEqual[l, 1.1e-61], 1.0, If[Or[LessEqual[l, 1.3e+24], N[Not[LessEqual[l, 4e+34]], $MachinePrecision]], N[Sqrt[N[(0.5 + N[(0.5 * N[(1.0 / N[(1.0 + N[(2.0 * N[(N[(ky * l), $MachinePrecision] / N[(N[(Om / l), $MachinePrecision] * N[(Om / ky), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 1.0]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 1.1 \cdot 10^{-61}:\\
\;\;\;\;1\\

\mathbf{elif}\;\ell \leq 1.3 \cdot 10^{+24} \lor \neg \left(\ell \leq 4 \cdot 10^{+34}\right):\\
\;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{1}{1 + 2 \cdot \frac{ky \cdot \ell}{\frac{Om}{\ell} \cdot \frac{Om}{ky}}}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < 1.10000000000000004e-61 or 1.2999999999999999e24 < l < 3.99999999999999978e34

    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. Step-by-step derivation
      1. expm1-log1p-u99.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.10000000000000004e-61 < l < 1.2999999999999999e24 or 3.99999999999999978e34 < l

    1. Initial program 93.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{0.5 + 0.5 \cdot \frac{1}{1 + 2 \cdot \color{blue}{\frac{\ell \cdot ky}{\frac{Om}{\ell} \cdot \frac{Om}{ky}}}}} \]
    10. Applied egg-rr90.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 1.1 \cdot 10^{-61}:\\ \;\;\;\;1\\ \mathbf{elif}\;\ell \leq 1.3 \cdot 10^{+24} \lor \neg \left(\ell \leq 4 \cdot 10^{+34}\right):\\ \;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{1}{1 + 2 \cdot \frac{ky \cdot \ell}{\frac{Om}{\ell} \cdot \frac{Om}{ky}}}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]

Alternative 6: 69.5% accurate, 5.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq 7.6 \cdot 10^{+34}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{1}{1 + 2 \cdot \left(\frac{\ell}{\frac{Om}{\ell}} \cdot \frac{ky \cdot ky}{Om}\right)}}\\ \end{array} \end{array} \]
(FPCore (l Om kx ky)
 :precision binary64
 (if (<= l 7.6e+34)
   1.0
   (sqrt
    (+
     0.5
     (* 0.5 (/ 1.0 (+ 1.0 (* 2.0 (* (/ l (/ Om l)) (/ (* ky ky) Om))))))))))
double code(double l, double Om, double kx, double ky) {
	double tmp;
	if (l <= 7.6e+34) {
		tmp = 1.0;
	} else {
		tmp = sqrt((0.5 + (0.5 * (1.0 / (1.0 + (2.0 * ((l / (Om / l)) * ((ky * ky) / Om))))))));
	}
	return tmp;
}
real(8) function code(l, om, kx, ky)
    real(8), intent (in) :: l
    real(8), intent (in) :: om
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8) :: tmp
    if (l <= 7.6d+34) then
        tmp = 1.0d0
    else
        tmp = sqrt((0.5d0 + (0.5d0 * (1.0d0 / (1.0d0 + (2.0d0 * ((l / (om / l)) * ((ky * ky) / om))))))))
    end if
    code = tmp
end function
public static double code(double l, double Om, double kx, double ky) {
	double tmp;
	if (l <= 7.6e+34) {
		tmp = 1.0;
	} else {
		tmp = Math.sqrt((0.5 + (0.5 * (1.0 / (1.0 + (2.0 * ((l / (Om / l)) * ((ky * ky) / Om))))))));
	}
	return tmp;
}
def code(l, Om, kx, ky):
	tmp = 0
	if l <= 7.6e+34:
		tmp = 1.0
	else:
		tmp = math.sqrt((0.5 + (0.5 * (1.0 / (1.0 + (2.0 * ((l / (Om / l)) * ((ky * ky) / Om))))))))
	return tmp
function code(l, Om, kx, ky)
	tmp = 0.0
	if (l <= 7.6e+34)
		tmp = 1.0;
	else
		tmp = sqrt(Float64(0.5 + Float64(0.5 * Float64(1.0 / Float64(1.0 + Float64(2.0 * Float64(Float64(l / Float64(Om / l)) * Float64(Float64(ky * ky) / Om))))))));
	end
	return tmp
end
function tmp_2 = code(l, Om, kx, ky)
	tmp = 0.0;
	if (l <= 7.6e+34)
		tmp = 1.0;
	else
		tmp = sqrt((0.5 + (0.5 * (1.0 / (1.0 + (2.0 * ((l / (Om / l)) * ((ky * ky) / Om))))))));
	end
	tmp_2 = tmp;
end
code[l_, Om_, kx_, ky_] := If[LessEqual[l, 7.6e+34], 1.0, N[Sqrt[N[(0.5 + N[(0.5 * N[(1.0 / N[(1.0 + N[(2.0 * N[(N[(l / N[(Om / l), $MachinePrecision]), $MachinePrecision] * N[(N[(ky * ky), $MachinePrecision] / Om), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 7.6 \cdot 10^{+34}:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{1}{1 + 2 \cdot \left(\frac{\ell}{\frac{Om}{\ell}} \cdot \frac{ky \cdot ky}{Om}\right)}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < 7.6000000000000003e34

    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. Step-by-step derivation
      1. expm1-log1p-u99.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 7.6000000000000003e34 < l

    1. Initial program 92.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 70.6% accurate, 6.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq 5 \cdot 10^{+35}:\\ \;\;\;\;1\\ \mathbf{elif}\;\ell \leq 2 \cdot 10^{+47}:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{elif}\;\ell \leq 10^{+70}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \end{array} \]
(FPCore (l Om kx ky)
 :precision binary64
 (if (<= l 5e+35)
   1.0
   (if (<= l 2e+47) (sqrt 0.5) (if (<= l 1e+70) 1.0 (sqrt 0.5)))))
double code(double l, double Om, double kx, double ky) {
	double tmp;
	if (l <= 5e+35) {
		tmp = 1.0;
	} else if (l <= 2e+47) {
		tmp = sqrt(0.5);
	} else if (l <= 1e+70) {
		tmp = 1.0;
	} else {
		tmp = sqrt(0.5);
	}
	return tmp;
}
real(8) function code(l, om, kx, ky)
    real(8), intent (in) :: l
    real(8), intent (in) :: om
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8) :: tmp
    if (l <= 5d+35) then
        tmp = 1.0d0
    else if (l <= 2d+47) then
        tmp = sqrt(0.5d0)
    else if (l <= 1d+70) then
        tmp = 1.0d0
    else
        tmp = sqrt(0.5d0)
    end if
    code = tmp
end function
public static double code(double l, double Om, double kx, double ky) {
	double tmp;
	if (l <= 5e+35) {
		tmp = 1.0;
	} else if (l <= 2e+47) {
		tmp = Math.sqrt(0.5);
	} else if (l <= 1e+70) {
		tmp = 1.0;
	} else {
		tmp = Math.sqrt(0.5);
	}
	return tmp;
}
def code(l, Om, kx, ky):
	tmp = 0
	if l <= 5e+35:
		tmp = 1.0
	elif l <= 2e+47:
		tmp = math.sqrt(0.5)
	elif l <= 1e+70:
		tmp = 1.0
	else:
		tmp = math.sqrt(0.5)
	return tmp
function code(l, Om, kx, ky)
	tmp = 0.0
	if (l <= 5e+35)
		tmp = 1.0;
	elseif (l <= 2e+47)
		tmp = sqrt(0.5);
	elseif (l <= 1e+70)
		tmp = 1.0;
	else
		tmp = sqrt(0.5);
	end
	return tmp
end
function tmp_2 = code(l, Om, kx, ky)
	tmp = 0.0;
	if (l <= 5e+35)
		tmp = 1.0;
	elseif (l <= 2e+47)
		tmp = sqrt(0.5);
	elseif (l <= 1e+70)
		tmp = 1.0;
	else
		tmp = sqrt(0.5);
	end
	tmp_2 = tmp;
end
code[l_, Om_, kx_, ky_] := If[LessEqual[l, 5e+35], 1.0, If[LessEqual[l, 2e+47], N[Sqrt[0.5], $MachinePrecision], If[LessEqual[l, 1e+70], 1.0, N[Sqrt[0.5], $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 5 \cdot 10^{+35}:\\
\;\;\;\;1\\

\mathbf{elif}\;\ell \leq 2 \cdot 10^{+47}:\\
\;\;\;\;\sqrt{0.5}\\

\mathbf{elif}\;\ell \leq 10^{+70}:\\
\;\;\;\;1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < 5.00000000000000021e35 or 2.0000000000000001e47 < l < 1.00000000000000007e70

    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. Step-by-step derivation
      1. expm1-log1p-u99.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.00000000000000021e35 < l < 2.0000000000000001e47 or 1.00000000000000007e70 < l

    1. Initial program 91.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. Simplified91.7%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 5 \cdot 10^{+35}:\\ \;\;\;\;1\\ \mathbf{elif}\;\ell \leq 2 \cdot 10^{+47}:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{elif}\;\ell \leq 10^{+70}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \]

Alternative 8: 62.4% accurate, 722.0× speedup?

\[\begin{array}{l} \\ 1 \end{array} \]
(FPCore (l Om kx ky) :precision binary64 1.0)
double code(double l, double Om, double kx, double ky) {
	return 1.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 = 1.0d0
end function
public static double code(double l, double Om, double kx, double ky) {
	return 1.0;
}
def code(l, Om, kx, ky):
	return 1.0
function code(l, Om, kx, ky)
	return 1.0
end
function tmp = code(l, Om, kx, ky)
	tmp = 1.0;
end
code[l_, Om_, kx_, ky_] := 1.0
\begin{array}{l}

\\
1
\end{array}
Derivation
  1. Initial program 97.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. Simplified97.7%

    \[\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. Step-by-step derivation
    1. expm1-log1p-u97.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{1} \]
  13. Final simplification65.5%

    \[\leadsto 1 \]

Reproduce

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