
(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:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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}
NOTE: l should be positive before calling this function
NOTE: Om should be positive before calling this function
NOTE: kx should be positive before calling this function
NOTE: ky should be positive before calling this function
NOTE: kx and ky should be sorted in increasing order before calling this function.
(FPCore (l Om kx ky)
:precision binary64
(sqrt
(*
(/ 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))))))))))l = abs(l);
Om = abs(Om);
kx = abs(kx);
ky = abs(ky);
assert(kx < ky);
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)))))))));
}
NOTE: l should be positive before calling this function
NOTE: Om should be positive before calling this function
NOTE: kx should be positive before calling this function
NOTE: ky should be positive before calling this function
NOTE: kx and ky should be sorted in increasing order before calling this function.
real(8) function code(l, om, kx, ky)
real(8), intent (in) :: l
real(8), intent (in) :: om
real(8), intent (in) :: kx
real(8), intent (in) :: ky
code = sqrt(((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
l = Math.abs(l);
Om = Math.abs(Om);
kx = Math.abs(kx);
ky = Math.abs(ky);
assert kx < ky;
public static double code(double l, double Om, double kx, double ky) {
return Math.sqrt(((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)))))))));
}
l = abs(l) Om = abs(Om) kx = abs(kx) ky = abs(ky) [kx, ky] = sort([kx, ky]) 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)))))))))
l = abs(l) Om = abs(Om) kx = abs(kx) ky = abs(ky) kx, ky = sort([kx, ky]) 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
l = abs(l)
Om = abs(Om)
kx = abs(kx)
ky = abs(ky)
kx, ky = num2cell(sort([kx, ky])){:}
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
NOTE: l should be positive before calling this function NOTE: Om should be positive before calling this function NOTE: kx should be positive before calling this function NOTE: ky should be positive before calling this function NOTE: kx and ky should be sorted in increasing order before calling this function. code[l_, Om_, kx_, ky_] := N[Sqrt[N[(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}
l = |l|\\
Om = |Om|\\
kx = |kx|\\
ky = |ky|\\
[kx, ky] = \mathsf{sort}([kx, ky])\\
\\
\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}
Initial program 98.4%
NOTE: l should be positive before calling this function
NOTE: Om should be positive before calling this function
NOTE: kx should be positive before calling this function
NOTE: ky should be positive before calling this function
NOTE: kx and ky should be sorted in increasing order before calling this function.
(FPCore (l Om kx ky)
:precision binary64
(sqrt
(+
0.5
(*
0.5
(/
1.0
(sqrt
(+
1.0
(*
(pow (/ 2.0 (/ Om l)) 2.0)
(+ (pow (sin kx) 2.0) (pow (sin ky) 2.0))))))))))l = abs(l);
Om = abs(Om);
kx = abs(kx);
ky = abs(ky);
assert(kx < ky);
double code(double l, double Om, double kx, double ky) {
return sqrt((0.5 + (0.5 * (1.0 / sqrt((1.0 + (pow((2.0 / (Om / l)), 2.0) * (pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))))))));
}
NOTE: l should be positive before calling this function
NOTE: Om should be positive before calling this function
NOTE: kx should be positive before calling this function
NOTE: ky should be positive before calling this function
NOTE: kx and ky should be sorted in increasing order before calling this function.
real(8) function code(l, om, kx, ky)
real(8), intent (in) :: l
real(8), intent (in) :: om
real(8), intent (in) :: kx
real(8), intent (in) :: ky
code = sqrt((0.5d0 + (0.5d0 * (1.0d0 / sqrt((1.0d0 + (((2.0d0 / (om / l)) ** 2.0d0) * ((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))))))))
end function
l = Math.abs(l);
Om = Math.abs(Om);
kx = Math.abs(kx);
ky = Math.abs(ky);
assert kx < ky;
public static double code(double l, double Om, double kx, double ky) {
return Math.sqrt((0.5 + (0.5 * (1.0 / Math.sqrt((1.0 + (Math.pow((2.0 / (Om / l)), 2.0) * (Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))))))));
}
l = abs(l) Om = abs(Om) kx = abs(kx) ky = abs(ky) [kx, ky] = sort([kx, ky]) def code(l, Om, kx, ky): return math.sqrt((0.5 + (0.5 * (1.0 / math.sqrt((1.0 + (math.pow((2.0 / (Om / l)), 2.0) * (math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))))))))
l = abs(l) Om = abs(Om) kx = abs(kx) ky = abs(ky) kx, ky = sort([kx, ky]) function code(l, Om, kx, ky) return sqrt(Float64(0.5 + Float64(0.5 * Float64(1.0 / sqrt(Float64(1.0 + Float64((Float64(2.0 / Float64(Om / l)) ^ 2.0) * Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0))))))))) end
l = abs(l)
Om = abs(Om)
kx = abs(kx)
ky = abs(ky)
kx, ky = num2cell(sort([kx, ky])){:}
function tmp = code(l, Om, kx, ky)
tmp = sqrt((0.5 + (0.5 * (1.0 / sqrt((1.0 + (((2.0 / (Om / l)) ^ 2.0) * ((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))))))));
end
NOTE: l should be positive before calling this function NOTE: Om should be positive before calling this function NOTE: kx should be positive before calling this function NOTE: ky should be positive before calling this function NOTE: kx and ky should be sorted in increasing order before calling this function. code[l_, Om_, kx_, ky_] := N[Sqrt[N[(0.5 + N[(0.5 * N[(1.0 / N[Sqrt[N[(1.0 + N[(N[Power[N[(2.0 / N[(Om / l), $MachinePrecision]), $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}
l = |l|\\
Om = |Om|\\
kx = |kx|\\
ky = |ky|\\
[kx, ky] = \mathsf{sort}([kx, ky])\\
\\
\sqrt{0.5 + 0.5 \cdot \frac{1}{\sqrt{1 + {\left(\frac{2}{\frac{Om}{\ell}}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}}}
\end{array}
Initial program 98.4%
NOTE: l should be positive before calling this function
NOTE: Om should be positive before calling this function
NOTE: kx should be positive before calling this function
NOTE: ky should be positive before calling this function
NOTE: kx and ky should be sorted in increasing order before calling this function.
(FPCore (l Om kx ky)
:precision binary64
(sqrt
(+
0.5
(/
0.5
(sqrt
(fma
(pow (* (/ 2.0 Om) l) 2.0)
(+ (pow (sin kx) 2.0) (pow (sin ky) 2.0))
1.0))))))l = abs(l);
Om = abs(Om);
kx = abs(kx);
ky = abs(ky);
assert(kx < ky);
double code(double l, double Om, double kx, double ky) {
return sqrt((0.5 + (0.5 / sqrt(fma(pow(((2.0 / Om) * l), 2.0), (pow(sin(kx), 2.0) + pow(sin(ky), 2.0)), 1.0)))));
}
l = abs(l) Om = abs(Om) kx = abs(kx) ky = abs(ky) kx, ky = sort([kx, ky]) function code(l, Om, kx, ky) return sqrt(Float64(0.5 + Float64(0.5 / sqrt(fma((Float64(Float64(2.0 / Om) * l) ^ 2.0), Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)), 1.0))))) end
NOTE: l should be positive before calling this function NOTE: Om should be positive before calling this function NOTE: kx should be positive before calling this function NOTE: ky should be positive before calling this function NOTE: kx and ky should be sorted in increasing order before calling this function. code[l_, Om_, kx_, ky_] := N[Sqrt[N[(0.5 + N[(0.5 / N[Sqrt[N[(N[Power[N[(N[(2.0 / Om), $MachinePrecision] * l), $MachinePrecision], 2.0], $MachinePrecision] * N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
l = |l|\\
Om = |Om|\\
kx = |kx|\\
ky = |ky|\\
[kx, ky] = \mathsf{sort}([kx, ky])\\
\\
\sqrt{0.5 + \frac{0.5}{\sqrt{\mathsf{fma}\left({\left(\frac{2}{Om} \cdot \ell\right)}^{2}, {\sin kx}^{2} + {\sin ky}^{2}, 1\right)}}}
\end{array}
Initial program 98.4%
NOTE: l should be positive before calling this function
NOTE: Om should be positive before calling this function
NOTE: kx should be positive before calling this function
NOTE: ky should be positive before calling this function
NOTE: kx and ky should be sorted in increasing order before calling this function.
(FPCore (l Om kx ky)
:precision binary64
(sqrt
(+
0.5
(/
0.5
(sqrt
(fma
(pow (* (/ l Om) 2.0) 2.0)
(+ (pow (sin kx) 2.0) (pow (sin ky) 2.0))
1.0))))))l = abs(l);
Om = abs(Om);
kx = abs(kx);
ky = abs(ky);
assert(kx < ky);
double code(double l, double Om, double kx, double ky) {
return sqrt((0.5 + (0.5 / sqrt(fma(pow(((l / Om) * 2.0), 2.0), (pow(sin(kx), 2.0) + pow(sin(ky), 2.0)), 1.0)))));
}
l = abs(l) Om = abs(Om) kx = abs(kx) ky = abs(ky) kx, ky = sort([kx, ky]) function code(l, Om, kx, ky) return sqrt(Float64(0.5 + Float64(0.5 / sqrt(fma((Float64(Float64(l / Om) * 2.0) ^ 2.0), Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)), 1.0))))) end
NOTE: l should be positive before calling this function NOTE: Om should be positive before calling this function NOTE: kx should be positive before calling this function NOTE: ky should be positive before calling this function NOTE: kx and ky should be sorted in increasing order before calling this function. code[l_, Om_, kx_, ky_] := N[Sqrt[N[(0.5 + N[(0.5 / N[Sqrt[N[(N[Power[N[(N[(l / Om), $MachinePrecision] * 2.0), $MachinePrecision], 2.0], $MachinePrecision] * N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
l = |l|\\
Om = |Om|\\
kx = |kx|\\
ky = |ky|\\
[kx, ky] = \mathsf{sort}([kx, ky])\\
\\
\sqrt{0.5 + \frac{0.5}{\sqrt{\mathsf{fma}\left({\left(\frac{\ell}{Om} \cdot 2\right)}^{2}, {\sin kx}^{2} + {\sin ky}^{2}, 1\right)}}}
\end{array}
Initial program 98.4%
herbie shell --seed 2023276
(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))))))))))