Toniolo and Linder, Equation (3a)

Percentage Accurate: 98.4% → 98.0%
Time: 14.9s
Alternatives: 7
Speedup: N/A×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 7 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 98.4% accurate, 1.0× speedup?

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

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

Alternative 1: 98.0% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{1 + \left({\sin kx}^{2} + {\sin ky}^{2}\right) \cdot \frac{\ell \cdot \left(\frac{\ell}{Om} \cdot 4\right)}{Om}}}\right)} \end{array} \]
(FPCore (l Om kx ky)
 :precision binary64
 (sqrt
  (*
   (/ 1.0 2.0)
   (+
    1.0
    (/
     1.0
     (sqrt
      (+
       1.0
       (*
        (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0))
        (/ (* l (* (/ l Om) 4.0)) Om)))))))))
double code(double l, double Om, double kx, double ky) {
	return sqrt(((1.0 / 2.0) * (1.0 + (1.0 / sqrt((1.0 + ((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)) * ((l * ((l / Om) * 4.0)) / Om))))))));
}
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 + (((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)) * ((l * ((l / om) * 4.0d0)) / om))))))))
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(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)) * ((l * ((l / Om) * 4.0)) / Om))))))));
}
def code(l, Om, kx, ky):
	return math.sqrt(((1.0 / 2.0) * (1.0 + (1.0 / math.sqrt((1.0 + ((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)) * ((l * ((l / Om) * 4.0)) / Om))))))))
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((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)) * Float64(Float64(l * Float64(Float64(l / Om) * 4.0)) / Om))))))))
end
function tmp = code(l, Om, kx, ky)
	tmp = sqrt(((1.0 / 2.0) * (1.0 + (1.0 / sqrt((1.0 + (((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)) * ((l * ((l / Om) * 4.0)) / Om))))))));
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[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(N[(l * N[(N[(l / Om), $MachinePrecision] * 4.0), $MachinePrecision]), $MachinePrecision] / Om), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{1 + \left({\sin kx}^{2} + {\sin ky}^{2}\right) \cdot \frac{\ell \cdot \left(\frac{\ell}{Om} \cdot 4\right)}{Om}}}\right)}
\end{array}
Derivation
  1. Initial program 99.6%

    \[\sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}}\right)} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-*.f64N/A

      \[\leadsto \sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{1 + {\left(\frac{\color{blue}{2 \cdot \ell}}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}}\right)} \]
    2. lift-/.f64N/A

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

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

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

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

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

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

    \[\leadsto \sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{1 + \left({\sin kx}^{2} + {\sin ky}^{2}\right) \cdot \frac{\ell \cdot \left(\frac{\ell}{Om} \cdot 4\right)}{Om}}}\right)} \]
  6. Add Preprocessing

Alternative 2: 89.5% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{1}{\sqrt{1 + \left({\sin kx}^{2} + {\sin ky}^{2}\right) \cdot {\left(\frac{2 \cdot \ell}{Om}\right)}^{2}}} \leq 2 \cdot 10^{-6}:\\ \;\;\;\;\sqrt{0.5 + \frac{0.5}{\sqrt{\mathsf{fma}\left(\frac{\ell \cdot \left(\frac{\ell}{Om} \cdot 4\right)}{Om}, \left(0.5 + -0.5\right) + ky \cdot ky, 1\right)}}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
(FPCore (l Om kx ky)
 :precision binary64
 (if (<=
      (/
       1.0
       (sqrt
        (+
         1.0
         (*
          (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0))
          (pow (/ (* 2.0 l) Om) 2.0)))))
      2e-6)
   (sqrt
    (+
     0.5
     (/
      0.5
      (sqrt
       (fma (/ (* l (* (/ l Om) 4.0)) Om) (+ (+ 0.5 -0.5) (* ky ky)) 1.0)))))
   1.0))
double code(double l, double Om, double kx, double ky) {
	double tmp;
	if ((1.0 / sqrt((1.0 + ((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)) * pow(((2.0 * l) / Om), 2.0))))) <= 2e-6) {
		tmp = sqrt((0.5 + (0.5 / sqrt(fma(((l * ((l / Om) * 4.0)) / Om), ((0.5 + -0.5) + (ky * ky)), 1.0)))));
	} else {
		tmp = 1.0;
	}
	return tmp;
}
function code(l, Om, kx, ky)
	tmp = 0.0
	if (Float64(1.0 / sqrt(Float64(1.0 + Float64(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)) * (Float64(Float64(2.0 * l) / Om) ^ 2.0))))) <= 2e-6)
		tmp = sqrt(Float64(0.5 + Float64(0.5 / sqrt(fma(Float64(Float64(l * Float64(Float64(l / Om) * 4.0)) / Om), Float64(Float64(0.5 + -0.5) + Float64(ky * ky)), 1.0)))));
	else
		tmp = 1.0;
	end
	return tmp
end
code[l_, Om_, kx_, ky_] := If[LessEqual[N[(1.0 / N[Sqrt[N[(1.0 + N[(N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[Power[N[(N[(2.0 * l), $MachinePrecision] / Om), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2e-6], N[Sqrt[N[(0.5 + N[(0.5 / N[Sqrt[N[(N[(N[(l * N[(N[(l / Om), $MachinePrecision] * 4.0), $MachinePrecision]), $MachinePrecision] / Om), $MachinePrecision] * N[(N[(0.5 + -0.5), $MachinePrecision] + N[(ky * ky), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 1.0]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{1}{\sqrt{1 + \left({\sin kx}^{2} + {\sin ky}^{2}\right) \cdot {\left(\frac{2 \cdot \ell}{Om}\right)}^{2}}} \leq 2 \cdot 10^{-6}:\\
\;\;\;\;\sqrt{0.5 + \frac{0.5}{\sqrt{\mathsf{fma}\left(\frac{\ell \cdot \left(\frac{\ell}{Om} \cdot 4\right)}{Om}, \left(0.5 + -0.5\right) + ky \cdot ky, 1\right)}}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 #s(literal 1 binary64) (*.f64 (pow.f64 (/.f64 (*.f64 #s(literal 2 binary64) l) Om) #s(literal 2 binary64)) (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))))) < 1.99999999999999991e-6

    1. Initial program 100.0%

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

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

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

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

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

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

      \[\leadsto \sqrt{\frac{\frac{1}{2}}{\sqrt{\mathsf{fma}\left(\frac{4 \cdot \left(\ell \cdot \ell\right)}{Om \cdot Om}, \left(\frac{1}{2} + \color{blue}{\frac{-1}{2}}\right) + ky \cdot ky, 1\right)}} + \frac{1}{2}} \]
    8. Step-by-step derivation
      1. Simplified77.3%

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

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

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

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

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

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

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

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

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

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

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

      if 1.99999999999999991e-6 < (/.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 #s(literal 1 binary64) (*.f64 (pow.f64 (/.f64 (*.f64 #s(literal 2 binary64) l) Om) #s(literal 2 binary64)) (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))))

      1. Initial program 99.2%

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

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

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

            \[\leadsto \color{blue}{1} \]
        3. Applied egg-rr98.7%

          \[\leadsto \color{blue}{1} \]
      5. Recombined 2 regimes into one program.
      6. Final simplification91.0%

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

      Alternative 3: 97.9% accurate, 1.1× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left({\sin kx}^{2} + {\sin ky}^{2}\right) \cdot {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \leq 2 \cdot 10^{-9}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \end{array} \]
      (FPCore (l Om kx ky)
       :precision binary64
       (if (<=
            (* (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)) (pow (/ (* 2.0 l) Om) 2.0))
            2e-9)
         1.0
         (sqrt 0.5)))
      double code(double l, double Om, double kx, double ky) {
      	double tmp;
      	if (((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)) * pow(((2.0 * l) / Om), 2.0)) <= 2e-9) {
      		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 ((((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)) * (((2.0d0 * l) / om) ** 2.0d0)) <= 2d-9) 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 (((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)) * Math.pow(((2.0 * l) / Om), 2.0)) <= 2e-9) {
      		tmp = 1.0;
      	} else {
      		tmp = Math.sqrt(0.5);
      	}
      	return tmp;
      }
      
      def code(l, Om, kx, ky):
      	tmp = 0
      	if ((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)) * math.pow(((2.0 * l) / Om), 2.0)) <= 2e-9:
      		tmp = 1.0
      	else:
      		tmp = math.sqrt(0.5)
      	return tmp
      
      function code(l, Om, kx, ky)
      	tmp = 0.0
      	if (Float64(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)) * (Float64(Float64(2.0 * l) / Om) ^ 2.0)) <= 2e-9)
      		tmp = 1.0;
      	else
      		tmp = sqrt(0.5);
      	end
      	return tmp
      end
      
      function tmp_2 = code(l, Om, kx, ky)
      	tmp = 0.0;
      	if ((((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)) * (((2.0 * l) / Om) ^ 2.0)) <= 2e-9)
      		tmp = 1.0;
      	else
      		tmp = sqrt(0.5);
      	end
      	tmp_2 = tmp;
      end
      
      code[l_, Om_, kx_, ky_] := If[LessEqual[N[(N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[Power[N[(N[(2.0 * l), $MachinePrecision] / Om), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], 2e-9], 1.0, N[Sqrt[0.5], $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;\left({\sin kx}^{2} + {\sin ky}^{2}\right) \cdot {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \leq 2 \cdot 10^{-9}:\\
      \;\;\;\;1\\
      
      \mathbf{else}:\\
      \;\;\;\;\sqrt{0.5}\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if (*.f64 (pow.f64 (/.f64 (*.f64 #s(literal 2 binary64) l) Om) #s(literal 2 binary64)) (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))) < 2.00000000000000012e-9

        1. Initial program 100.0%

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

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

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

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

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

          if 2.00000000000000012e-9 < (*.f64 (pow.f64 (/.f64 (*.f64 #s(literal 2 binary64) l) Om) #s(literal 2 binary64)) (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))

          1. Initial program 99.2%

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

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

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

            \[\leadsto \begin{array}{l} \mathbf{if}\;\left({\sin kx}^{2} + {\sin ky}^{2}\right) \cdot {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \leq 2 \cdot 10^{-9}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \]
          7. Add Preprocessing

          Alternative 4: 91.3% accurate, 1.8× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\ell}{Om} \cdot 4\\ \mathbf{if}\;\frac{2 \cdot \ell}{Om} \leq 5 \cdot 10^{+15}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(1 + \frac{1}{\sqrt{\mathsf{fma}\left(t\_0, \frac{\ell}{Om} \cdot \mathsf{fma}\left(-0.5, \cos \left(ky \cdot -2\right) + \cos \left(kx \cdot -2\right), 1\right), 1\right)}}\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 + \frac{0.5}{\sqrt{\mathsf{fma}\left(\frac{\ell \cdot t\_0}{Om}, \left(0.5 + -0.5\right) + ky \cdot ky, 1\right)}}}\\ \end{array} \end{array} \]
          (FPCore (l Om kx ky)
           :precision binary64
           (let* ((t_0 (* (/ l Om) 4.0)))
             (if (<= (/ (* 2.0 l) Om) 5e+15)
               (sqrt
                (*
                 0.5
                 (+
                  1.0
                  (/
                   1.0
                   (sqrt
                    (fma
                     t_0
                     (* (/ l Om) (fma -0.5 (+ (cos (* ky -2.0)) (cos (* kx -2.0))) 1.0))
                     1.0))))))
               (sqrt
                (+
                 0.5
                 (/
                  0.5
                  (sqrt (fma (/ (* l t_0) Om) (+ (+ 0.5 -0.5) (* ky ky)) 1.0))))))))
          double code(double l, double Om, double kx, double ky) {
          	double t_0 = (l / Om) * 4.0;
          	double tmp;
          	if (((2.0 * l) / Om) <= 5e+15) {
          		tmp = sqrt((0.5 * (1.0 + (1.0 / sqrt(fma(t_0, ((l / Om) * fma(-0.5, (cos((ky * -2.0)) + cos((kx * -2.0))), 1.0)), 1.0))))));
          	} else {
          		tmp = sqrt((0.5 + (0.5 / sqrt(fma(((l * t_0) / Om), ((0.5 + -0.5) + (ky * ky)), 1.0)))));
          	}
          	return tmp;
          }
          
          function code(l, Om, kx, ky)
          	t_0 = Float64(Float64(l / Om) * 4.0)
          	tmp = 0.0
          	if (Float64(Float64(2.0 * l) / Om) <= 5e+15)
          		tmp = sqrt(Float64(0.5 * Float64(1.0 + Float64(1.0 / sqrt(fma(t_0, Float64(Float64(l / Om) * fma(-0.5, Float64(cos(Float64(ky * -2.0)) + cos(Float64(kx * -2.0))), 1.0)), 1.0))))));
          	else
          		tmp = sqrt(Float64(0.5 + Float64(0.5 / sqrt(fma(Float64(Float64(l * t_0) / Om), Float64(Float64(0.5 + -0.5) + Float64(ky * ky)), 1.0)))));
          	end
          	return tmp
          end
          
          code[l_, Om_, kx_, ky_] := Block[{t$95$0 = N[(N[(l / Om), $MachinePrecision] * 4.0), $MachinePrecision]}, If[LessEqual[N[(N[(2.0 * l), $MachinePrecision] / Om), $MachinePrecision], 5e+15], N[Sqrt[N[(0.5 * N[(1.0 + N[(1.0 / N[Sqrt[N[(t$95$0 * N[(N[(l / Om), $MachinePrecision] * N[(-0.5 * N[(N[Cos[N[(ky * -2.0), $MachinePrecision]], $MachinePrecision] + N[Cos[N[(kx * -2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[N[(0.5 + N[(0.5 / N[Sqrt[N[(N[(N[(l * t$95$0), $MachinePrecision] / Om), $MachinePrecision] * N[(N[(0.5 + -0.5), $MachinePrecision] + N[(ky * ky), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          t_0 := \frac{\ell}{Om} \cdot 4\\
          \mathbf{if}\;\frac{2 \cdot \ell}{Om} \leq 5 \cdot 10^{+15}:\\
          \;\;\;\;\sqrt{0.5 \cdot \left(1 + \frac{1}{\sqrt{\mathsf{fma}\left(t\_0, \frac{\ell}{Om} \cdot \mathsf{fma}\left(-0.5, \cos \left(ky \cdot -2\right) + \cos \left(kx \cdot -2\right), 1\right), 1\right)}}\right)}\\
          
          \mathbf{else}:\\
          \;\;\;\;\sqrt{0.5 + \frac{0.5}{\sqrt{\mathsf{fma}\left(\frac{\ell \cdot t\_0}{Om}, \left(0.5 + -0.5\right) + ky \cdot ky, 1\right)}}}\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if (/.f64 (*.f64 #s(literal 2 binary64) l) Om) < 5e15

            1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                \[\leadsto \sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{\mathsf{fma}\left(\frac{\ell}{Om} \cdot 4, \frac{\ell}{Om} \cdot \mathsf{fma}\left(\frac{-1}{2}, \cos \left(ky \cdot -2\right) + \cos \color{blue}{\left(kx \cdot -2\right)}, 1\right), 1\right)}}\right)} \]
              17. lower-*.f6494.5

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

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

            if 5e15 < (/.f64 (*.f64 #s(literal 2 binary64) l) Om)

            1. Initial program 100.0%

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

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

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

                \[\leadsto \sqrt{\frac{\frac{1}{2}}{\sqrt{\mathsf{fma}\left(\frac{4 \cdot \left(\ell \cdot \ell\right)}{Om \cdot Om}, \left(\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(kx + kx\right)\right) + \color{blue}{ky \cdot ky}, 1\right)}} + \frac{1}{2}} \]
              2. lower-*.f6485.8

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

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

              \[\leadsto \sqrt{\frac{\frac{1}{2}}{\sqrt{\mathsf{fma}\left(\frac{4 \cdot \left(\ell \cdot \ell\right)}{Om \cdot Om}, \left(\frac{1}{2} + \color{blue}{\frac{-1}{2}}\right) + ky \cdot ky, 1\right)}} + \frac{1}{2}} \]
            8. Step-by-step derivation
              1. Simplified76.1%

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

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

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

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

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

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

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

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

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

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

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

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

            Alternative 5: 84.4% accurate, 2.8× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{2 \cdot \ell}{Om} \leq 5 \cdot 10^{+15}:\\ \;\;\;\;\sqrt{0.5 + \frac{0.5}{\sqrt{\mathsf{fma}\left(\frac{\ell \cdot \frac{\ell \cdot 4}{Om}}{Om}, \mathsf{fma}\left(-0.5, \cos \left(ky \cdot -2\right), 0.5\right), 1\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 + \frac{0.5}{\sqrt{\mathsf{fma}\left(\frac{\ell \cdot \left(\frac{\ell}{Om} \cdot 4\right)}{Om}, \left(0.5 + -0.5\right) + ky \cdot ky, 1\right)}}}\\ \end{array} \end{array} \]
            (FPCore (l Om kx ky)
             :precision binary64
             (if (<= (/ (* 2.0 l) Om) 5e+15)
               (sqrt
                (+
                 0.5
                 (/
                  0.5
                  (sqrt
                   (fma
                    (/ (* l (/ (* l 4.0) Om)) Om)
                    (fma -0.5 (cos (* ky -2.0)) 0.5)
                    1.0)))))
               (sqrt
                (+
                 0.5
                 (/
                  0.5
                  (sqrt
                   (fma (/ (* l (* (/ l Om) 4.0)) Om) (+ (+ 0.5 -0.5) (* ky ky)) 1.0)))))))
            double code(double l, double Om, double kx, double ky) {
            	double tmp;
            	if (((2.0 * l) / Om) <= 5e+15) {
            		tmp = sqrt((0.5 + (0.5 / sqrt(fma(((l * ((l * 4.0) / Om)) / Om), fma(-0.5, cos((ky * -2.0)), 0.5), 1.0)))));
            	} else {
            		tmp = sqrt((0.5 + (0.5 / sqrt(fma(((l * ((l / Om) * 4.0)) / Om), ((0.5 + -0.5) + (ky * ky)), 1.0)))));
            	}
            	return tmp;
            }
            
            function code(l, Om, kx, ky)
            	tmp = 0.0
            	if (Float64(Float64(2.0 * l) / Om) <= 5e+15)
            		tmp = sqrt(Float64(0.5 + Float64(0.5 / sqrt(fma(Float64(Float64(l * Float64(Float64(l * 4.0) / Om)) / Om), fma(-0.5, cos(Float64(ky * -2.0)), 0.5), 1.0)))));
            	else
            		tmp = sqrt(Float64(0.5 + Float64(0.5 / sqrt(fma(Float64(Float64(l * Float64(Float64(l / Om) * 4.0)) / Om), Float64(Float64(0.5 + -0.5) + Float64(ky * ky)), 1.0)))));
            	end
            	return tmp
            end
            
            code[l_, Om_, kx_, ky_] := If[LessEqual[N[(N[(2.0 * l), $MachinePrecision] / Om), $MachinePrecision], 5e+15], N[Sqrt[N[(0.5 + N[(0.5 / N[Sqrt[N[(N[(N[(l * N[(N[(l * 4.0), $MachinePrecision] / Om), $MachinePrecision]), $MachinePrecision] / Om), $MachinePrecision] * N[(-0.5 * N[Cos[N[(ky * -2.0), $MachinePrecision]], $MachinePrecision] + 0.5), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[N[(0.5 + N[(0.5 / N[Sqrt[N[(N[(N[(l * N[(N[(l / Om), $MachinePrecision] * 4.0), $MachinePrecision]), $MachinePrecision] / Om), $MachinePrecision] * N[(N[(0.5 + -0.5), $MachinePrecision] + N[(ky * ky), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            \mathbf{if}\;\frac{2 \cdot \ell}{Om} \leq 5 \cdot 10^{+15}:\\
            \;\;\;\;\sqrt{0.5 + \frac{0.5}{\sqrt{\mathsf{fma}\left(\frac{\ell \cdot \frac{\ell \cdot 4}{Om}}{Om}, \mathsf{fma}\left(-0.5, \cos \left(ky \cdot -2\right), 0.5\right), 1\right)}}}\\
            
            \mathbf{else}:\\
            \;\;\;\;\sqrt{0.5 + \frac{0.5}{\sqrt{\mathsf{fma}\left(\frac{\ell \cdot \left(\frac{\ell}{Om} \cdot 4\right)}{Om}, \left(0.5 + -0.5\right) + ky \cdot ky, 1\right)}}}\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 2 regimes
            2. if (/.f64 (*.f64 #s(literal 2 binary64) l) Om) < 5e15

              1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

                  \[\leadsto \sqrt{\frac{\frac{1}{2}}{\sqrt{\mathsf{fma}\left(\frac{4 \cdot \left(\ell \cdot \ell\right)}{Om \cdot Om}, \mathsf{fma}\left(\frac{-1}{2}, \cos \color{blue}{\left(ky \cdot -2\right)}, \frac{1}{2}\right), 1\right)}} + \frac{1}{2}} \]
                8. lower-*.f6475.5

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              if 5e15 < (/.f64 (*.f64 #s(literal 2 binary64) l) Om)

              1. Initial program 100.0%

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

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

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

                  \[\leadsto \sqrt{\frac{\frac{1}{2}}{\sqrt{\mathsf{fma}\left(\frac{4 \cdot \left(\ell \cdot \ell\right)}{Om \cdot Om}, \left(\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(kx + kx\right)\right) + \color{blue}{ky \cdot ky}, 1\right)}} + \frac{1}{2}} \]
                2. lower-*.f6485.8

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

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

                \[\leadsto \sqrt{\frac{\frac{1}{2}}{\sqrt{\mathsf{fma}\left(\frac{4 \cdot \left(\ell \cdot \ell\right)}{Om \cdot Om}, \left(\frac{1}{2} + \color{blue}{\frac{-1}{2}}\right) + ky \cdot ky, 1\right)}} + \frac{1}{2}} \]
              8. Step-by-step derivation
                1. Simplified76.1%

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

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

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

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

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

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

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

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

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

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

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

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

              Alternative 6: 84.0% accurate, 2.9× speedup?

              \[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\ell \cdot \left(\frac{\ell}{Om} \cdot 4\right)}{Om}\\ \mathbf{if}\;\frac{2 \cdot \ell}{Om} \leq 50000000000000:\\ \;\;\;\;\sqrt{0.5 + \frac{0.5}{\sqrt{\mathsf{fma}\left(t\_0, \mathsf{fma}\left(-0.5, \cos \left(-ky\right), 0.5\right), 1\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 + \frac{0.5}{\sqrt{\mathsf{fma}\left(t\_0, \left(0.5 + -0.5\right) + ky \cdot ky, 1\right)}}}\\ \end{array} \end{array} \]
              (FPCore (l Om kx ky)
               :precision binary64
               (let* ((t_0 (/ (* l (* (/ l Om) 4.0)) Om)))
                 (if (<= (/ (* 2.0 l) Om) 50000000000000.0)
                   (sqrt (+ 0.5 (/ 0.5 (sqrt (fma t_0 (fma -0.5 (cos (- ky)) 0.5) 1.0)))))
                   (sqrt (+ 0.5 (/ 0.5 (sqrt (fma t_0 (+ (+ 0.5 -0.5) (* ky ky)) 1.0))))))))
              double code(double l, double Om, double kx, double ky) {
              	double t_0 = (l * ((l / Om) * 4.0)) / Om;
              	double tmp;
              	if (((2.0 * l) / Om) <= 50000000000000.0) {
              		tmp = sqrt((0.5 + (0.5 / sqrt(fma(t_0, fma(-0.5, cos(-ky), 0.5), 1.0)))));
              	} else {
              		tmp = sqrt((0.5 + (0.5 / sqrt(fma(t_0, ((0.5 + -0.5) + (ky * ky)), 1.0)))));
              	}
              	return tmp;
              }
              
              function code(l, Om, kx, ky)
              	t_0 = Float64(Float64(l * Float64(Float64(l / Om) * 4.0)) / Om)
              	tmp = 0.0
              	if (Float64(Float64(2.0 * l) / Om) <= 50000000000000.0)
              		tmp = sqrt(Float64(0.5 + Float64(0.5 / sqrt(fma(t_0, fma(-0.5, cos(Float64(-ky)), 0.5), 1.0)))));
              	else
              		tmp = sqrt(Float64(0.5 + Float64(0.5 / sqrt(fma(t_0, Float64(Float64(0.5 + -0.5) + Float64(ky * ky)), 1.0)))));
              	end
              	return tmp
              end
              
              code[l_, Om_, kx_, ky_] := Block[{t$95$0 = N[(N[(l * N[(N[(l / Om), $MachinePrecision] * 4.0), $MachinePrecision]), $MachinePrecision] / Om), $MachinePrecision]}, If[LessEqual[N[(N[(2.0 * l), $MachinePrecision] / Om), $MachinePrecision], 50000000000000.0], N[Sqrt[N[(0.5 + N[(0.5 / N[Sqrt[N[(t$95$0 * N[(-0.5 * N[Cos[(-ky)], $MachinePrecision] + 0.5), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[N[(0.5 + N[(0.5 / N[Sqrt[N[(t$95$0 * N[(N[(0.5 + -0.5), $MachinePrecision] + N[(ky * ky), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
              
              \begin{array}{l}
              
              \\
              \begin{array}{l}
              t_0 := \frac{\ell \cdot \left(\frac{\ell}{Om} \cdot 4\right)}{Om}\\
              \mathbf{if}\;\frac{2 \cdot \ell}{Om} \leq 50000000000000:\\
              \;\;\;\;\sqrt{0.5 + \frac{0.5}{\sqrt{\mathsf{fma}\left(t\_0, \mathsf{fma}\left(-0.5, \cos \left(-ky\right), 0.5\right), 1\right)}}}\\
              
              \mathbf{else}:\\
              \;\;\;\;\sqrt{0.5 + \frac{0.5}{\sqrt{\mathsf{fma}\left(t\_0, \left(0.5 + -0.5\right) + ky \cdot ky, 1\right)}}}\\
              
              
              \end{array}
              \end{array}
              
              Derivation
              1. Split input into 2 regimes
              2. if (/.f64 (*.f64 #s(literal 2 binary64) l) Om) < 5e13

                1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

                    \[\leadsto \sqrt{\frac{\frac{1}{2}}{\sqrt{\mathsf{fma}\left(\frac{4 \cdot \left(\ell \cdot \ell\right)}{Om \cdot Om}, \mathsf{fma}\left(\frac{-1}{2}, \cos \color{blue}{\left(ky \cdot -2\right)}, \frac{1}{2}\right), 1\right)}} + \frac{1}{2}} \]
                  8. lower-*.f6475.5

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

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

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

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

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

                  \[\leadsto \sqrt{\frac{0.5}{\sqrt{\mathsf{fma}\left(\frac{4 \cdot \left(\ell \cdot \ell\right)}{Om \cdot Om}, \mathsf{fma}\left(-0.5, \cos \color{blue}{\left(-ky\right)}, 0.5\right), 1\right)}} + 0.5} \]
                10. Step-by-step derivation
                  1. associate-*r*N/A

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

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

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

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

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

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

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

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

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

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

                if 5e13 < (/.f64 (*.f64 #s(literal 2 binary64) l) Om)

                1. Initial program 100.0%

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

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

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

                    \[\leadsto \sqrt{\frac{\frac{1}{2}}{\sqrt{\mathsf{fma}\left(\frac{4 \cdot \left(\ell \cdot \ell\right)}{Om \cdot Om}, \left(\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(kx + kx\right)\right) + \color{blue}{ky \cdot ky}, 1\right)}} + \frac{1}{2}} \]
                  2. lower-*.f6485.8

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

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

                  \[\leadsto \sqrt{\frac{\frac{1}{2}}{\sqrt{\mathsf{fma}\left(\frac{4 \cdot \left(\ell \cdot \ell\right)}{Om \cdot Om}, \left(\frac{1}{2} + \color{blue}{\frac{-1}{2}}\right) + ky \cdot ky, 1\right)}} + \frac{1}{2}} \]
                8. Step-by-step derivation
                  1. Simplified76.1%

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

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

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

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

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

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

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

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

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

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

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

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

                Alternative 7: 63.2% accurate, 581.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 99.6%

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

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

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

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

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

                  Reproduce

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