Average Error: 1.0 → 0.8
Time: 11.9s
Precision: binary64
\[\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)} \]
\[\begin{array}{l} t_0 := \sqrt{0.5 + \sqrt{\frac{0.25}{\mathsf{fma}\left(4 \cdot {\left(\frac{\ell}{Om}\right)}^{2}, {\left(\mathsf{hypot}\left(\sin kx, \sin ky\right)\right)}^{2}, 1\right)}}}\\ \mathbf{if}\;\sin kx \leq -5.98664871367318 \cdot 10^{-76}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\sin kx \leq -5.174496557575073 \cdot 10^{-305}:\\ \;\;\;\;\sqrt{0.5 + \frac{0.5}{\log \left(e^{\sqrt{\mathsf{fma}\left({\left(\frac{\ell \cdot \sin ky}{Om}\right)}^{2}, 4, 1\right)}}\right)}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \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))))))))))
(FPCore (l Om kx ky)
 :precision binary64
 (let* ((t_0
         (sqrt
          (+
           0.5
           (sqrt
            (/
             0.25
             (fma
              (* 4.0 (pow (/ l Om) 2.0))
              (pow (hypot (sin kx) (sin ky)) 2.0)
              1.0)))))))
   (if (<= (sin kx) -5.98664871367318e-76)
     t_0
     (if (<= (sin kx) -5.174496557575073e-305)
       (sqrt
        (+
         0.5
         (/
          0.5
          (log (exp (sqrt (fma (pow (/ (* l (sin ky)) Om) 2.0) 4.0 1.0)))))))
       t_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)))))))));
}
double code(double l, double Om, double kx, double ky) {
	double t_0 = sqrt((0.5 + sqrt((0.25 / fma((4.0 * pow((l / Om), 2.0)), pow(hypot(sin(kx), sin(ky)), 2.0), 1.0)))));
	double tmp;
	if (sin(kx) <= -5.98664871367318e-76) {
		tmp = t_0;
	} else if (sin(kx) <= -5.174496557575073e-305) {
		tmp = sqrt((0.5 + (0.5 / log(exp(sqrt(fma(pow(((l * sin(ky)) / Om), 2.0), 4.0, 1.0)))))));
	} else {
		tmp = t_0;
	}
	return tmp;
}
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 code(l, Om, kx, ky)
	t_0 = sqrt(Float64(0.5 + sqrt(Float64(0.25 / fma(Float64(4.0 * (Float64(l / Om) ^ 2.0)), (hypot(sin(kx), sin(ky)) ^ 2.0), 1.0)))))
	tmp = 0.0
	if (sin(kx) <= -5.98664871367318e-76)
		tmp = t_0;
	elseif (sin(kx) <= -5.174496557575073e-305)
		tmp = sqrt(Float64(0.5 + Float64(0.5 / log(exp(sqrt(fma((Float64(Float64(l * sin(ky)) / Om) ^ 2.0), 4.0, 1.0)))))));
	else
		tmp = t_0;
	end
	return tmp
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]
code[l_, Om_, kx_, ky_] := Block[{t$95$0 = N[Sqrt[N[(0.5 + N[Sqrt[N[(0.25 / N[(N[(4.0 * N[Power[N[(l / Om), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[Power[N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision], 2.0], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[Sin[kx], $MachinePrecision], -5.98664871367318e-76], t$95$0, If[LessEqual[N[Sin[kx], $MachinePrecision], -5.174496557575073e-305], N[Sqrt[N[(0.5 + N[(0.5 / N[Log[N[Exp[N[Sqrt[N[(N[Power[N[(N[(l * N[Sin[ky], $MachinePrecision]), $MachinePrecision] / Om), $MachinePrecision], 2.0], $MachinePrecision] * 4.0 + 1.0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], t$95$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)}
\begin{array}{l}
t_0 := \sqrt{0.5 + \sqrt{\frac{0.25}{\mathsf{fma}\left(4 \cdot {\left(\frac{\ell}{Om}\right)}^{2}, {\left(\mathsf{hypot}\left(\sin kx, \sin ky\right)\right)}^{2}, 1\right)}}}\\
\mathbf{if}\;\sin kx \leq -5.98664871367318 \cdot 10^{-76}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\sin kx \leq -5.174496557575073 \cdot 10^{-305}:\\
\;\;\;\;\sqrt{0.5 + \frac{0.5}{\log \left(e^{\sqrt{\mathsf{fma}\left({\left(\frac{\ell \cdot \sin ky}{Om}\right)}^{2}, 4, 1\right)}}\right)}}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}

Error

Bits error versus l

Bits error versus Om

Bits error versus kx

Bits error versus ky

Derivation

  1. Split input into 2 regimes
  2. if (sin.f64 kx) < -5.98664871367318051e-76 or -5.1744965575750725e-305 < (sin.f64 kx)

    1. Initial program 0.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. Simplified0.7

      \[\leadsto \color{blue}{\sqrt{0.5 + \frac{0.5}{\sqrt{\mathsf{fma}\left({\left(2 \cdot \frac{\ell}{Om}\right)}^{2}, {\sin kx}^{2} + {\sin ky}^{2}, 1\right)}}}} \]
    3. Applied egg-rr0.7

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

    if -5.98664871367318051e-76 < (sin.f64 kx) < -5.1744965575750725e-305

    1. Initial program 2.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. Simplified2.2

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

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

      \[\leadsto \sqrt{0.5 + \frac{0.5}{\color{blue}{\sqrt{\mathsf{fma}\left(\frac{\ell \cdot \ell}{Om} \cdot \frac{{\sin ky}^{2}}{Om}, 4, 1\right)}}}} \]
    5. Applied egg-rr3.9

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

      \[\leadsto \sqrt{0.5 + \frac{0.5}{\color{blue}{\log \left(e^{\sqrt{\mathsf{fma}\left({\left(\frac{\ell \cdot \sin ky}{Om}\right)}^{2}, 4, 1\right)}}\right)}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin kx \leq -5.98664871367318 \cdot 10^{-76}:\\ \;\;\;\;\sqrt{0.5 + \sqrt{\frac{0.25}{\mathsf{fma}\left(4 \cdot {\left(\frac{\ell}{Om}\right)}^{2}, {\left(\mathsf{hypot}\left(\sin kx, \sin ky\right)\right)}^{2}, 1\right)}}}\\ \mathbf{elif}\;\sin kx \leq -5.174496557575073 \cdot 10^{-305}:\\ \;\;\;\;\sqrt{0.5 + \frac{0.5}{\log \left(e^{\sqrt{\mathsf{fma}\left({\left(\frac{\ell \cdot \sin ky}{Om}\right)}^{2}, 4, 1\right)}}\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 + \sqrt{\frac{0.25}{\mathsf{fma}\left(4 \cdot {\left(\frac{\ell}{Om}\right)}^{2}, {\left(\mathsf{hypot}\left(\sin kx, \sin ky\right)\right)}^{2}, 1\right)}}}\\ \end{array} \]

Reproduce

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