Average Error: 1.0 → 0.5
Time: 11.1s
Precision: binary64
\[ \begin{array}{c}[kx, ky] = \mathsf{sort}([kx, ky])\\ \end{array} \]
\[\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{\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 -2 \cdot 10^{-80}:\\ \;\;\;\;\sqrt{0.5 + \frac{-0.5}{-t_0}}\\ \mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-289}:\\ \;\;\;\;\sqrt{0.5 + \mathsf{log1p}\left(\mathsf{expm1}\left(\frac{0.5}{\sqrt{\mathsf{fma}\left({\left(\frac{\ell \cdot \sin ky}{Om}\right)}^{2}, 4, 1\right)}}\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 + \log \left(e^{\frac{0.5}{t_0}}\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))))))))))
(FPCore (l Om kx ky)
 :precision binary64
 (let* ((t_0
         (sqrt
          (fma
           (* 4.0 (pow (/ l Om) 2.0))
           (pow (hypot (sin kx) (sin ky)) 2.0)
           1.0))))
   (if (<= (sin kx) -2e-80)
     (sqrt (+ 0.5 (/ -0.5 (- t_0))))
     (if (<= (sin kx) 5e-289)
       (sqrt
        (+
         0.5
         (log1p
          (expm1
           (/ 0.5 (sqrt (fma (pow (/ (* l (sin ky)) Om) 2.0) 4.0 1.0)))))))
       (sqrt (+ 0.5 (log (exp (/ 0.5 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(fma((4.0 * pow((l / Om), 2.0)), pow(hypot(sin(kx), sin(ky)), 2.0), 1.0));
	double tmp;
	if (sin(kx) <= -2e-80) {
		tmp = sqrt((0.5 + (-0.5 / -t_0)));
	} else if (sin(kx) <= 5e-289) {
		tmp = sqrt((0.5 + log1p(expm1((0.5 / sqrt(fma(pow(((l * sin(ky)) / Om), 2.0), 4.0, 1.0)))))));
	} else {
		tmp = sqrt((0.5 + log(exp((0.5 / 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(fma(Float64(4.0 * (Float64(l / Om) ^ 2.0)), (hypot(sin(kx), sin(ky)) ^ 2.0), 1.0))
	tmp = 0.0
	if (sin(kx) <= -2e-80)
		tmp = sqrt(Float64(0.5 + Float64(-0.5 / Float64(-t_0))));
	elseif (sin(kx) <= 5e-289)
		tmp = sqrt(Float64(0.5 + log1p(expm1(Float64(0.5 / sqrt(fma((Float64(Float64(l * sin(ky)) / Om) ^ 2.0), 4.0, 1.0)))))));
	else
		tmp = sqrt(Float64(0.5 + log(exp(Float64(0.5 / 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[(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]}, If[LessEqual[N[Sin[kx], $MachinePrecision], -2e-80], N[Sqrt[N[(0.5 + N[(-0.5 / (-t$95$0)), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Sin[kx], $MachinePrecision], 5e-289], N[Sqrt[N[(0.5 + N[Log[1 + N[(Exp[N[(0.5 / 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]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[N[(0.5 + N[Log[N[Exp[N[(0.5 / t$95$0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]
\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{\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 -2 \cdot 10^{-80}:\\
\;\;\;\;\sqrt{0.5 + \frac{-0.5}{-t_0}}\\

\mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-289}:\\
\;\;\;\;\sqrt{0.5 + \mathsf{log1p}\left(\mathsf{expm1}\left(\frac{0.5}{\sqrt{\mathsf{fma}\left({\left(\frac{\ell \cdot \sin ky}{Om}\right)}^{2}, 4, 1\right)}}\right)\right)}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 + \log \left(e^{\frac{0.5}{t_0}}\right)}\\


\end{array}

Error

Bits error versus l

Bits error versus Om

Bits error versus kx

Bits error versus ky

Derivation

  1. Split input into 3 regimes
  2. if (sin.f64 kx) < -1.99999999999999992e-80

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

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

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

      \[\leadsto \sqrt{0.5 + \color{blue}{\frac{-0.5}{-\sqrt{\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 -1.99999999999999992e-80 < (sin.f64 kx) < 5.00000000000000029e-289

    1. Initial program 3.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. Simplified3.4

      \[\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 15.3

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

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

      \[\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 + \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{0.5}{\sqrt{\mathsf{fma}\left({\left(\frac{\ell \cdot \sin ky}{Om}\right)}^{2}, 4, 1\right)}}\right)\right)}} \]

    if 5.00000000000000029e-289 < (sin.f64 kx)

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin kx \leq -2 \cdot 10^{-80}:\\ \;\;\;\;\sqrt{0.5 + \frac{-0.5}{-\sqrt{\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 \cdot 10^{-289}:\\ \;\;\;\;\sqrt{0.5 + \mathsf{log1p}\left(\mathsf{expm1}\left(\frac{0.5}{\sqrt{\mathsf{fma}\left({\left(\frac{\ell \cdot \sin ky}{Om}\right)}^{2}, 4, 1\right)}}\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 + \log \left(e^{\frac{0.5}{\sqrt{\mathsf{fma}\left(4 \cdot {\left(\frac{\ell}{Om}\right)}^{2}, {\left(\mathsf{hypot}\left(\sin kx, \sin ky\right)\right)}^{2}, 1\right)}}}\right)}\\ \end{array} \]

Reproduce

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