
(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 3 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: 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 (hypot 1.0 (* (* -2.0 l) (/ (sin ky) 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 / hypot(1.0, ((-2.0 * l) * (sin(ky) / 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 / Math.hypot(1.0, ((-2.0 * l) * (Math.sin(ky) / 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 / math.hypot(1.0, ((-2.0 * l) * (math.sin(ky) / 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 / hypot(1.0, Float64(Float64(-2.0 * l) * Float64(sin(ky) / Om)))))) end
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 / hypot(1.0, ((-2.0 * l) * (sin(ky) / Om))))));
end
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[1.0 ^ 2 + N[(N[(-2.0 * l), $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / Om), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
kx = |kx|\\
ky = |ky|\\
[kx, ky] = \mathsf{sort}([kx, ky])\\
\\
\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, \left(-2 \cdot \ell\right) \cdot \frac{\sin ky}{Om}\right)}}
\end{array}
Initial program 98.4%
Simplified98.4%
Taylor expanded in kx around 0 74.6%
associate-*r/74.6%
unpow274.6%
times-frac82.3%
unpow282.3%
associate-*l*84.2%
Simplified84.2%
*-commutative84.2%
clear-num84.2%
un-div-inv84.2%
associate-*r*82.3%
pow282.3%
pow-prod-down89.2%
div-inv89.2%
metadata-eval89.2%
Applied egg-rr89.2%
associate-/r*82.5%
Simplified82.5%
remove-double-neg82.5%
neg-sub082.5%
+-commutative82.5%
Applied egg-rr93.9%
neg-sub093.9%
remove-double-neg93.9%
+-commutative93.9%
unpow293.9%
hypot-1-def93.9%
associate-/r/93.9%
Simplified93.9%
associate-*l/93.9%
metadata-eval93.9%
div-inv93.9%
associate-*l*93.9%
*-commutative93.9%
div-inv93.9%
associate-/r/93.9%
*-commutative93.9%
Applied egg-rr93.9%
associate-*r*93.9%
Simplified93.9%
Final simplification93.9%
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 (if (<= Om 2.85e+23) (sqrt 0.5) 1.0))
kx = abs(kx);
ky = abs(ky);
assert(kx < ky);
double code(double l, double Om, double kx, double ky) {
double tmp;
if (Om <= 2.85e+23) {
tmp = sqrt(0.5);
} else {
tmp = 1.0;
}
return tmp;
}
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
real(8) :: tmp
if (om <= 2.85d+23) then
tmp = sqrt(0.5d0)
else
tmp = 1.0d0
end if
code = tmp
end function
kx = Math.abs(kx);
ky = Math.abs(ky);
assert kx < ky;
public static double code(double l, double Om, double kx, double ky) {
double tmp;
if (Om <= 2.85e+23) {
tmp = Math.sqrt(0.5);
} else {
tmp = 1.0;
}
return tmp;
}
kx = abs(kx) ky = abs(ky) [kx, ky] = sort([kx, ky]) def code(l, Om, kx, ky): tmp = 0 if Om <= 2.85e+23: tmp = math.sqrt(0.5) else: tmp = 1.0 return tmp
kx = abs(kx) ky = abs(ky) kx, ky = sort([kx, ky]) function code(l, Om, kx, ky) tmp = 0.0 if (Om <= 2.85e+23) tmp = sqrt(0.5); else tmp = 1.0; end return tmp end
kx = abs(kx)
ky = abs(ky)
kx, ky = num2cell(sort([kx, ky])){:}
function tmp_2 = code(l, Om, kx, ky)
tmp = 0.0;
if (Om <= 2.85e+23)
tmp = sqrt(0.5);
else
tmp = 1.0;
end
tmp_2 = tmp;
end
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_] := If[LessEqual[Om, 2.85e+23], N[Sqrt[0.5], $MachinePrecision], 1.0]
\begin{array}{l}
kx = |kx|\\
ky = |ky|\\
[kx, ky] = \mathsf{sort}([kx, ky])\\
\\
\begin{array}{l}
\mathbf{if}\;Om \leq 2.85 \cdot 10^{+23}:\\
\;\;\;\;\sqrt{0.5}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if Om < 2.85e23Initial program 98.0%
Simplified98.0%
Taylor expanded in l around inf 55.8%
associate-*r*55.8%
*-commutative55.8%
associate-*l*55.8%
unpow255.8%
unpow255.8%
hypot-def57.8%
Simplified57.8%
Taylor expanded in l around inf 64.5%
if 2.85e23 < Om Initial program 100.0%
Simplified100.0%
Taylor expanded in kx around 0 87.6%
associate-*r/87.6%
unpow287.6%
times-frac93.3%
unpow293.3%
associate-*l*94.2%
Simplified94.2%
*-commutative94.2%
clear-num94.2%
un-div-inv94.2%
associate-*r*93.3%
pow293.3%
pow-prod-down94.2%
div-inv94.2%
metadata-eval94.2%
Applied egg-rr94.2%
associate-/r*90.2%
Simplified90.2%
remove-double-neg90.2%
neg-sub090.2%
+-commutative90.2%
Applied egg-rr95.6%
neg-sub095.6%
remove-double-neg95.6%
+-commutative95.6%
unpow295.6%
hypot-1-def95.6%
associate-/r/95.6%
Simplified95.6%
Taylor expanded in Om around inf 81.1%
Final simplification68.0%
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))
kx = abs(kx);
ky = abs(ky);
assert(kx < ky);
double code(double l, double Om, double kx, double ky) {
return sqrt(0.5);
}
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)
end function
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);
}
kx = abs(kx) ky = abs(ky) [kx, ky] = sort([kx, ky]) def code(l, Om, kx, ky): return math.sqrt(0.5)
kx = abs(kx) ky = abs(ky) kx, ky = sort([kx, ky]) function code(l, Om, kx, ky) return sqrt(0.5) end
kx = abs(kx)
ky = abs(ky)
kx, ky = num2cell(sort([kx, ky])){:}
function tmp = code(l, Om, kx, ky)
tmp = sqrt(0.5);
end
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[0.5], $MachinePrecision]
\begin{array}{l}
kx = |kx|\\
ky = |ky|\\
[kx, ky] = \mathsf{sort}([kx, ky])\\
\\
\sqrt{0.5}
\end{array}
Initial program 98.4%
Simplified98.4%
Taylor expanded in l around inf 48.9%
associate-*r*48.9%
*-commutative48.9%
associate-*l*48.9%
unpow248.9%
unpow248.9%
hypot-def50.5%
Simplified50.5%
Taylor expanded in l around inf 58.6%
Final simplification58.6%
herbie shell --seed 2023297
(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))))))))))