
(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 6 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}
(FPCore (l Om kx ky) :precision binary64 (pow (pow (+ 0.5 (/ 0.5 (hypot 1.0 (* 2.0 (* (/ l Om) (hypot (sin kx) (sin ky))))))) 1.5) 0.3333333333333333))
double code(double l, double Om, double kx, double ky) {
return pow(pow((0.5 + (0.5 / hypot(1.0, (2.0 * ((l / Om) * hypot(sin(kx), sin(ky))))))), 1.5), 0.3333333333333333);
}
public static double code(double l, double Om, double kx, double ky) {
return Math.pow(Math.pow((0.5 + (0.5 / Math.hypot(1.0, (2.0 * ((l / Om) * Math.hypot(Math.sin(kx), Math.sin(ky))))))), 1.5), 0.3333333333333333);
}
def code(l, Om, kx, ky): return math.pow(math.pow((0.5 + (0.5 / math.hypot(1.0, (2.0 * ((l / Om) * math.hypot(math.sin(kx), math.sin(ky))))))), 1.5), 0.3333333333333333)
function code(l, Om, kx, ky) return (Float64(0.5 + Float64(0.5 / hypot(1.0, Float64(2.0 * Float64(Float64(l / Om) * hypot(sin(kx), sin(ky))))))) ^ 1.5) ^ 0.3333333333333333 end
function tmp = code(l, Om, kx, ky) tmp = ((0.5 + (0.5 / hypot(1.0, (2.0 * ((l / Om) * hypot(sin(kx), sin(ky))))))) ^ 1.5) ^ 0.3333333333333333; end
code[l_, Om_, kx_, ky_] := N[Power[N[Power[N[(0.5 + N[(0.5 / N[Sqrt[1.0 ^ 2 + N[(2.0 * N[(N[(l / Om), $MachinePrecision] * N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.5], $MachinePrecision], 0.3333333333333333], $MachinePrecision]
\begin{array}{l}
\\
{\left({\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, 2 \cdot \left(\frac{\ell}{Om} \cdot \mathsf{hypot}\left(\sin kx, \sin ky\right)\right)\right)}\right)}^{1.5}\right)}^{0.3333333333333333}
\end{array}
Initial program 99.2%
Simplified99.2%
expm1-log1p-u99.2%
expm1-udef99.2%
Applied egg-rr100.0%
expm1-def100.0%
expm1-log1p100.0%
*-commutative100.0%
associate-*r/100.0%
Simplified100.0%
add-cbrt-cube99.9%
pow1/3100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (l Om kx ky) :precision binary64 (sqrt (+ 0.5 (/ 0.5 (hypot 1.0 (* 2.0 (* (/ l Om) (hypot (sin kx) (sin ky)))))))))
double code(double l, double Om, double kx, double ky) {
return sqrt((0.5 + (0.5 / hypot(1.0, (2.0 * ((l / Om) * hypot(sin(kx), sin(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 / Om) * Math.hypot(Math.sin(kx), Math.sin(ky))))))));
}
def code(l, Om, kx, ky): return math.sqrt((0.5 + (0.5 / math.hypot(1.0, (2.0 * ((l / Om) * math.hypot(math.sin(kx), math.sin(ky))))))))
function code(l, Om, kx, ky) return sqrt(Float64(0.5 + Float64(0.5 / hypot(1.0, Float64(2.0 * Float64(Float64(l / Om) * hypot(sin(kx), sin(ky)))))))) end
function tmp = code(l, Om, kx, ky) tmp = sqrt((0.5 + (0.5 / hypot(1.0, (2.0 * ((l / Om) * hypot(sin(kx), sin(ky)))))))); end
code[l_, Om_, kx_, ky_] := N[Sqrt[N[(0.5 + N[(0.5 / N[Sqrt[1.0 ^ 2 + N[(2.0 * N[(N[(l / Om), $MachinePrecision] * N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, 2 \cdot \left(\frac{\ell}{Om} \cdot \mathsf{hypot}\left(\sin kx, \sin ky\right)\right)\right)}}
\end{array}
Initial program 99.2%
Simplified99.2%
expm1-log1p-u99.2%
expm1-udef99.2%
Applied egg-rr100.0%
expm1-def100.0%
expm1-log1p100.0%
*-commutative100.0%
associate-*r/100.0%
Simplified100.0%
expm1-log1p-u99.3%
expm1-udef99.3%
Applied egg-rr99.3%
expm1-def99.3%
expm1-log1p100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (l Om kx ky) :precision binary64 (if (<= l 3.8e+208) (sqrt (+ 0.5 (/ 0.5 (hypot 1.0 (* 2.0 (/ l (/ Om (sin kx)))))))) (sqrt 0.5)))
double code(double l, double Om, double kx, double ky) {
double tmp;
if (l <= 3.8e+208) {
tmp = sqrt((0.5 + (0.5 / hypot(1.0, (2.0 * (l / (Om / sin(kx))))))));
} else {
tmp = sqrt(0.5);
}
return tmp;
}
public static double code(double l, double Om, double kx, double ky) {
double tmp;
if (l <= 3.8e+208) {
tmp = Math.sqrt((0.5 + (0.5 / Math.hypot(1.0, (2.0 * (l / (Om / Math.sin(kx))))))));
} else {
tmp = Math.sqrt(0.5);
}
return tmp;
}
def code(l, Om, kx, ky): tmp = 0 if l <= 3.8e+208: tmp = math.sqrt((0.5 + (0.5 / math.hypot(1.0, (2.0 * (l / (Om / math.sin(kx)))))))) else: tmp = math.sqrt(0.5) return tmp
function code(l, Om, kx, ky) tmp = 0.0 if (l <= 3.8e+208) tmp = sqrt(Float64(0.5 + Float64(0.5 / hypot(1.0, Float64(2.0 * Float64(l / Float64(Om / sin(kx)))))))); else tmp = sqrt(0.5); end return tmp end
function tmp_2 = code(l, Om, kx, ky) tmp = 0.0; if (l <= 3.8e+208) tmp = sqrt((0.5 + (0.5 / hypot(1.0, (2.0 * (l / (Om / sin(kx)))))))); else tmp = sqrt(0.5); end tmp_2 = tmp; end
code[l_, Om_, kx_, ky_] := If[LessEqual[l, 3.8e+208], N[Sqrt[N[(0.5 + N[(0.5 / N[Sqrt[1.0 ^ 2 + N[(2.0 * N[(l / N[(Om / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[0.5], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 3.8 \cdot 10^{+208}:\\
\;\;\;\;\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, 2 \cdot \frac{\ell}{\frac{Om}{\sin kx}}\right)}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if l < 3.8000000000000002e208Initial program 99.5%
Simplified99.5%
Taylor expanded in ky around 0 84.3%
associate-/l*84.3%
associate-/r/84.3%
associate-*l*84.3%
metadata-eval84.3%
unpow284.3%
unpow284.3%
times-frac92.6%
swap-sqr92.6%
unpow292.6%
swap-sqr95.1%
hypot-1-def95.1%
*-commutative95.1%
associate-*r/95.1%
Simplified95.1%
expm1-log1p-u94.5%
expm1-udef94.5%
*-commutative94.5%
div-inv94.5%
*-commutative94.5%
associate-*r/94.5%
associate-*l*94.5%
Applied egg-rr94.5%
expm1-def94.5%
expm1-log1p95.1%
associate-*l/95.1%
associate-/l*95.1%
Simplified95.1%
if 3.8000000000000002e208 < l Initial program 96.6%
Simplified96.6%
Taylor expanded in ky around 0 69.0%
associate-/l*69.0%
associate-/r/69.0%
associate-*l*69.0%
metadata-eval69.0%
unpow269.0%
unpow269.0%
times-frac84.1%
swap-sqr84.1%
unpow284.1%
swap-sqr89.0%
hypot-1-def89.0%
*-commutative89.0%
associate-*r/89.0%
Simplified89.0%
Taylor expanded in l around inf 94.5%
Final simplification95.0%
(FPCore (l Om kx ky) :precision binary64 (sqrt (+ 0.5 (/ 0.5 (hypot 1.0 (* 2.0 (/ (* l (sin ky)) Om)))))))
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))))));
}
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))))));
}
def code(l, Om, kx, ky): return math.sqrt((0.5 + (0.5 / math.hypot(1.0, (2.0 * ((l * math.sin(ky)) / Om))))))
function code(l, Om, kx, ky) return sqrt(Float64(0.5 + Float64(0.5 / hypot(1.0, Float64(2.0 * Float64(Float64(l * sin(ky)) / Om)))))) end
function tmp = code(l, Om, kx, ky) tmp = sqrt((0.5 + (0.5 / hypot(1.0, (2.0 * ((l * sin(ky)) / Om)))))); end
code[l_, Om_, kx_, ky_] := N[Sqrt[N[(0.5 + N[(0.5 / N[Sqrt[1.0 ^ 2 + N[(2.0 * N[(N[(l * N[Sin[ky], $MachinePrecision]), $MachinePrecision] / Om), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, 2 \cdot \frac{\ell \cdot \sin ky}{Om}\right)}}
\end{array}
Initial program 99.2%
Simplified99.2%
expm1-log1p-u99.2%
expm1-udef99.2%
Applied egg-rr100.0%
expm1-def100.0%
expm1-log1p100.0%
*-commutative100.0%
associate-*r/100.0%
Simplified100.0%
expm1-log1p-u99.3%
expm1-udef99.3%
Applied egg-rr99.3%
expm1-def99.3%
expm1-log1p100.0%
Simplified100.0%
Taylor expanded in kx around 0 92.0%
Final simplification92.0%
(FPCore (l Om kx ky) :precision binary64 (if (<= Om 1.1e-14) (sqrt 0.5) (if (<= Om 6200000000.0) 1.0 (if (<= Om 2e+45) (sqrt 0.5) 1.0))))
double code(double l, double Om, double kx, double ky) {
double tmp;
if (Om <= 1.1e-14) {
tmp = sqrt(0.5);
} else if (Om <= 6200000000.0) {
tmp = 1.0;
} else if (Om <= 2e+45) {
tmp = sqrt(0.5);
} else {
tmp = 1.0;
}
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 (om <= 1.1d-14) then
tmp = sqrt(0.5d0)
else if (om <= 6200000000.0d0) then
tmp = 1.0d0
else if (om <= 2d+45) then
tmp = sqrt(0.5d0)
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double l, double Om, double kx, double ky) {
double tmp;
if (Om <= 1.1e-14) {
tmp = Math.sqrt(0.5);
} else if (Om <= 6200000000.0) {
tmp = 1.0;
} else if (Om <= 2e+45) {
tmp = Math.sqrt(0.5);
} else {
tmp = 1.0;
}
return tmp;
}
def code(l, Om, kx, ky): tmp = 0 if Om <= 1.1e-14: tmp = math.sqrt(0.5) elif Om <= 6200000000.0: tmp = 1.0 elif Om <= 2e+45: tmp = math.sqrt(0.5) else: tmp = 1.0 return tmp
function code(l, Om, kx, ky) tmp = 0.0 if (Om <= 1.1e-14) tmp = sqrt(0.5); elseif (Om <= 6200000000.0) tmp = 1.0; elseif (Om <= 2e+45) tmp = sqrt(0.5); else tmp = 1.0; end return tmp end
function tmp_2 = code(l, Om, kx, ky) tmp = 0.0; if (Om <= 1.1e-14) tmp = sqrt(0.5); elseif (Om <= 6200000000.0) tmp = 1.0; elseif (Om <= 2e+45) tmp = sqrt(0.5); else tmp = 1.0; end tmp_2 = tmp; end
code[l_, Om_, kx_, ky_] := If[LessEqual[Om, 1.1e-14], N[Sqrt[0.5], $MachinePrecision], If[LessEqual[Om, 6200000000.0], 1.0, If[LessEqual[Om, 2e+45], N[Sqrt[0.5], $MachinePrecision], 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;Om \leq 1.1 \cdot 10^{-14}:\\
\;\;\;\;\sqrt{0.5}\\
\mathbf{elif}\;Om \leq 6200000000:\\
\;\;\;\;1\\
\mathbf{elif}\;Om \leq 2 \cdot 10^{+45}:\\
\;\;\;\;\sqrt{0.5}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if Om < 1.1e-14 or 6.2e9 < Om < 1.9999999999999999e45Initial program 98.9%
Simplified98.9%
Taylor expanded in ky around 0 83.0%
associate-/l*83.0%
associate-/r/83.0%
associate-*l*83.0%
metadata-eval83.0%
unpow283.0%
unpow283.0%
times-frac89.9%
swap-sqr89.9%
unpow289.9%
swap-sqr93.6%
hypot-1-def93.6%
*-commutative93.6%
associate-*r/93.6%
Simplified93.6%
Taylor expanded in l around inf 66.0%
if 1.1e-14 < Om < 6.2e9 or 1.9999999999999999e45 < Om Initial program 100.0%
Simplified100.0%
expm1-log1p-u100.0%
expm1-udef100.0%
Applied egg-rr100.0%
expm1-def100.0%
expm1-log1p100.0%
*-commutative100.0%
associate-*r/100.0%
Simplified100.0%
expm1-log1p-u99.8%
expm1-udef99.8%
Applied egg-rr99.8%
expm1-def99.8%
expm1-log1p100.0%
Simplified100.0%
Taylor expanded in l around 0 87.9%
Final simplification72.0%
(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}
Initial program 99.2%
Simplified99.2%
expm1-log1p-u99.2%
expm1-udef99.2%
Applied egg-rr100.0%
expm1-def100.0%
expm1-log1p100.0%
*-commutative100.0%
associate-*r/100.0%
Simplified100.0%
expm1-log1p-u99.3%
expm1-udef99.3%
Applied egg-rr99.3%
expm1-def99.3%
expm1-log1p100.0%
Simplified100.0%
Taylor expanded in l around 0 61.7%
Final simplification61.7%
herbie shell --seed 2024010
(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))))))))))