
(FPCore (k n) :precision binary64 (* (/ 1.0 (sqrt k)) (pow (* (* 2.0 PI) n) (/ (- 1.0 k) 2.0))))
double code(double k, double n) {
return (1.0 / sqrt(k)) * pow(((2.0 * ((double) M_PI)) * n), ((1.0 - k) / 2.0));
}
public static double code(double k, double n) {
return (1.0 / Math.sqrt(k)) * Math.pow(((2.0 * Math.PI) * n), ((1.0 - k) / 2.0));
}
def code(k, n): return (1.0 / math.sqrt(k)) * math.pow(((2.0 * math.pi) * n), ((1.0 - k) / 2.0))
function code(k, n) return Float64(Float64(1.0 / sqrt(k)) * (Float64(Float64(2.0 * pi) * n) ^ Float64(Float64(1.0 - k) / 2.0))) end
function tmp = code(k, n) tmp = (1.0 / sqrt(k)) * (((2.0 * pi) * n) ^ ((1.0 - k) / 2.0)); end
code[k_, n_] := N[(N[(1.0 / N[Sqrt[k], $MachinePrecision]), $MachinePrecision] * N[Power[N[(N[(2.0 * Pi), $MachinePrecision] * n), $MachinePrecision], N[(N[(1.0 - k), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (k n) :precision binary64 (* (/ 1.0 (sqrt k)) (pow (* (* 2.0 PI) n) (/ (- 1.0 k) 2.0))))
double code(double k, double n) {
return (1.0 / sqrt(k)) * pow(((2.0 * ((double) M_PI)) * n), ((1.0 - k) / 2.0));
}
public static double code(double k, double n) {
return (1.0 / Math.sqrt(k)) * Math.pow(((2.0 * Math.PI) * n), ((1.0 - k) / 2.0));
}
def code(k, n): return (1.0 / math.sqrt(k)) * math.pow(((2.0 * math.pi) * n), ((1.0 - k) / 2.0))
function code(k, n) return Float64(Float64(1.0 / sqrt(k)) * (Float64(Float64(2.0 * pi) * n) ^ Float64(Float64(1.0 - k) / 2.0))) end
function tmp = code(k, n) tmp = (1.0 / sqrt(k)) * (((2.0 * pi) * n) ^ ((1.0 - k) / 2.0)); end
code[k_, n_] := N[(N[(1.0 / N[Sqrt[k], $MachinePrecision]), $MachinePrecision] * N[Power[N[(N[(2.0 * Pi), $MachinePrecision] * n), $MachinePrecision], N[(N[(1.0 - k), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)}
\end{array}
(FPCore (k n) :precision binary64 (/ (pow k -0.5) (pow (* 2.0 (* PI n)) (+ -0.5 (/ k 2.0)))))
double code(double k, double n) {
return pow(k, -0.5) / pow((2.0 * (((double) M_PI) * n)), (-0.5 + (k / 2.0)));
}
public static double code(double k, double n) {
return Math.pow(k, -0.5) / Math.pow((2.0 * (Math.PI * n)), (-0.5 + (k / 2.0)));
}
def code(k, n): return math.pow(k, -0.5) / math.pow((2.0 * (math.pi * n)), (-0.5 + (k / 2.0)))
function code(k, n) return Float64((k ^ -0.5) / (Float64(2.0 * Float64(pi * n)) ^ Float64(-0.5 + Float64(k / 2.0)))) end
function tmp = code(k, n) tmp = (k ^ -0.5) / ((2.0 * (pi * n)) ^ (-0.5 + (k / 2.0))); end
code[k_, n_] := N[(N[Power[k, -0.5], $MachinePrecision] / N[Power[N[(2.0 * N[(Pi * n), $MachinePrecision]), $MachinePrecision], N[(-0.5 + N[(k / 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{k}^{-0.5}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(-0.5 + \frac{k}{2}\right)}}
\end{array}
Initial program 99.2%
associate-*r*N/A
div-subN/A
metadata-evalN/A
pow-subN/A
clear-numN/A
un-div-invN/A
/-lowering-/.f64N/A
inv-powN/A
pow1/2N/A
pow-powN/A
pow-lowering-pow.f64N/A
metadata-evalN/A
clear-numN/A
pow-subN/A
Applied egg-rr99.3%
Final simplification99.3%
(FPCore (k n)
:precision binary64
(let* ((t_0 (/ 2.0 (/ k (* PI n)))))
(if (<= k 3e+163)
(* (sqrt n) (sqrt (* 2.0 (/ PI k))))
(pow (* t_0 t_0) 0.25))))
double code(double k, double n) {
double t_0 = 2.0 / (k / (((double) M_PI) * n));
double tmp;
if (k <= 3e+163) {
tmp = sqrt(n) * sqrt((2.0 * (((double) M_PI) / k)));
} else {
tmp = pow((t_0 * t_0), 0.25);
}
return tmp;
}
public static double code(double k, double n) {
double t_0 = 2.0 / (k / (Math.PI * n));
double tmp;
if (k <= 3e+163) {
tmp = Math.sqrt(n) * Math.sqrt((2.0 * (Math.PI / k)));
} else {
tmp = Math.pow((t_0 * t_0), 0.25);
}
return tmp;
}
def code(k, n): t_0 = 2.0 / (k / (math.pi * n)) tmp = 0 if k <= 3e+163: tmp = math.sqrt(n) * math.sqrt((2.0 * (math.pi / k))) else: tmp = math.pow((t_0 * t_0), 0.25) return tmp
function code(k, n) t_0 = Float64(2.0 / Float64(k / Float64(pi * n))) tmp = 0.0 if (k <= 3e+163) tmp = Float64(sqrt(n) * sqrt(Float64(2.0 * Float64(pi / k)))); else tmp = Float64(t_0 * t_0) ^ 0.25; end return tmp end
function tmp_2 = code(k, n) t_0 = 2.0 / (k / (pi * n)); tmp = 0.0; if (k <= 3e+163) tmp = sqrt(n) * sqrt((2.0 * (pi / k))); else tmp = (t_0 * t_0) ^ 0.25; end tmp_2 = tmp; end
code[k_, n_] := Block[{t$95$0 = N[(2.0 / N[(k / N[(Pi * n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[k, 3e+163], N[(N[Sqrt[n], $MachinePrecision] * N[Sqrt[N[(2.0 * N[(Pi / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Power[N[(t$95$0 * t$95$0), $MachinePrecision], 0.25], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2}{\frac{k}{\pi \cdot n}}\\
\mathbf{if}\;k \leq 3 \cdot 10^{+163}:\\
\;\;\;\;\sqrt{n} \cdot \sqrt{2 \cdot \frac{\pi}{k}}\\
\mathbf{else}:\\
\;\;\;\;{\left(t\_0 \cdot t\_0\right)}^{0.25}\\
\end{array}
\end{array}
if k < 3.00000000000000013e163Initial program 98.9%
Taylor expanded in k around 0
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
PI-lowering-PI.f64N/A
sqrt-lowering-sqrt.f6448.1%
Simplified48.1%
sqrt-unprodN/A
associate-/l*N/A
associate-*l*N/A
sqrt-prodN/A
pow1/2N/A
*-lowering-*.f64N/A
pow1/2N/A
sqrt-lowering-sqrt.f64N/A
sqrt-lowering-sqrt.f64N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
PI-lowering-PI.f6457.7%
Applied egg-rr57.7%
if 3.00000000000000013e163 < k Initial program 100.0%
Taylor expanded in k around 0
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
PI-lowering-PI.f64N/A
sqrt-lowering-sqrt.f642.7%
Simplified2.7%
sqrt-unprodN/A
sqrt-lowering-sqrt.f64N/A
clear-numN/A
associate-*l/N/A
metadata-evalN/A
/-lowering-/.f64N/A
*-commutativeN/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
PI-lowering-PI.f642.7%
Applied egg-rr2.7%
pow1/2N/A
sqr-powN/A
pow-prod-downN/A
pow-lowering-pow.f64N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
PI-lowering-PI.f64N/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
PI-lowering-PI.f64N/A
metadata-eval18.1%
Applied egg-rr18.1%
Final simplification48.1%
(FPCore (k n) :precision binary64 (/ (pow (* 2.0 (* PI n)) (- 0.5 (/ k 2.0))) (sqrt k)))
double code(double k, double n) {
return pow((2.0 * (((double) M_PI) * n)), (0.5 - (k / 2.0))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.pow((2.0 * (Math.PI * n)), (0.5 - (k / 2.0))) / Math.sqrt(k);
}
def code(k, n): return math.pow((2.0 * (math.pi * n)), (0.5 - (k / 2.0))) / math.sqrt(k)
function code(k, n) return Float64((Float64(2.0 * Float64(pi * n)) ^ Float64(0.5 - Float64(k / 2.0))) / sqrt(k)) end
function tmp = code(k, n) tmp = ((2.0 * (pi * n)) ^ (0.5 - (k / 2.0))) / sqrt(k); end
code[k_, n_] := N[(N[Power[N[(2.0 * N[(Pi * n), $MachinePrecision]), $MachinePrecision], N[(0.5 - N[(k / 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(0.5 - \frac{k}{2}\right)}}{\sqrt{k}}
\end{array}
Initial program 99.2%
associate-*l/N/A
*-lft-identityN/A
/-lowering-/.f64N/A
pow-lowering-pow.f64N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
PI-lowering-PI.f64N/A
div-subN/A
--lowering--.f64N/A
metadata-evalN/A
/-lowering-/.f64N/A
sqrt-lowering-sqrt.f6499.3%
Simplified99.3%
(FPCore (k n) :precision binary64 (let* ((t_0 (/ k (* PI n))) (t_1 (/ 2.0 t_0))) (if (<= k 6.6e+161) (pow (/ t_0 2.0) -0.5) (pow (* t_1 t_1) 0.25))))
double code(double k, double n) {
double t_0 = k / (((double) M_PI) * n);
double t_1 = 2.0 / t_0;
double tmp;
if (k <= 6.6e+161) {
tmp = pow((t_0 / 2.0), -0.5);
} else {
tmp = pow((t_1 * t_1), 0.25);
}
return tmp;
}
public static double code(double k, double n) {
double t_0 = k / (Math.PI * n);
double t_1 = 2.0 / t_0;
double tmp;
if (k <= 6.6e+161) {
tmp = Math.pow((t_0 / 2.0), -0.5);
} else {
tmp = Math.pow((t_1 * t_1), 0.25);
}
return tmp;
}
def code(k, n): t_0 = k / (math.pi * n) t_1 = 2.0 / t_0 tmp = 0 if k <= 6.6e+161: tmp = math.pow((t_0 / 2.0), -0.5) else: tmp = math.pow((t_1 * t_1), 0.25) return tmp
function code(k, n) t_0 = Float64(k / Float64(pi * n)) t_1 = Float64(2.0 / t_0) tmp = 0.0 if (k <= 6.6e+161) tmp = Float64(t_0 / 2.0) ^ -0.5; else tmp = Float64(t_1 * t_1) ^ 0.25; end return tmp end
function tmp_2 = code(k, n) t_0 = k / (pi * n); t_1 = 2.0 / t_0; tmp = 0.0; if (k <= 6.6e+161) tmp = (t_0 / 2.0) ^ -0.5; else tmp = (t_1 * t_1) ^ 0.25; end tmp_2 = tmp; end
code[k_, n_] := Block[{t$95$0 = N[(k / N[(Pi * n), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(2.0 / t$95$0), $MachinePrecision]}, If[LessEqual[k, 6.6e+161], N[Power[N[(t$95$0 / 2.0), $MachinePrecision], -0.5], $MachinePrecision], N[Power[N[(t$95$1 * t$95$1), $MachinePrecision], 0.25], $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{k}{\pi \cdot n}\\
t_1 := \frac{2}{t\_0}\\
\mathbf{if}\;k \leq 6.6 \cdot 10^{+161}:\\
\;\;\;\;{\left(\frac{t\_0}{2}\right)}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;{\left(t\_1 \cdot t\_1\right)}^{0.25}\\
\end{array}
\end{array}
if k < 6.59999999999999995e161Initial program 98.9%
Taylor expanded in k around 0
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
PI-lowering-PI.f64N/A
sqrt-lowering-sqrt.f6448.3%
Simplified48.3%
sqrt-unprodN/A
sqrt-lowering-sqrt.f64N/A
clear-numN/A
associate-*l/N/A
metadata-evalN/A
/-lowering-/.f64N/A
*-commutativeN/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
PI-lowering-PI.f6448.4%
Applied egg-rr48.4%
clear-numN/A
inv-powN/A
sqrt-pow1N/A
metadata-evalN/A
metadata-evalN/A
pow-lowering-pow.f64N/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
PI-lowering-PI.f64N/A
metadata-eval50.4%
Applied egg-rr50.4%
if 6.59999999999999995e161 < k Initial program 100.0%
Taylor expanded in k around 0
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
PI-lowering-PI.f64N/A
sqrt-lowering-sqrt.f642.7%
Simplified2.7%
sqrt-unprodN/A
sqrt-lowering-sqrt.f64N/A
clear-numN/A
associate-*l/N/A
metadata-evalN/A
/-lowering-/.f64N/A
*-commutativeN/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
PI-lowering-PI.f642.7%
Applied egg-rr2.7%
pow1/2N/A
sqr-powN/A
pow-prod-downN/A
pow-lowering-pow.f64N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
PI-lowering-PI.f64N/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
PI-lowering-PI.f64N/A
metadata-eval17.8%
Applied egg-rr17.8%
(FPCore (k n) :precision binary64 (pow (/ (/ k (* PI n)) 2.0) -0.5))
double code(double k, double n) {
return pow(((k / (((double) M_PI) * n)) / 2.0), -0.5);
}
public static double code(double k, double n) {
return Math.pow(((k / (Math.PI * n)) / 2.0), -0.5);
}
def code(k, n): return math.pow(((k / (math.pi * n)) / 2.0), -0.5)
function code(k, n) return Float64(Float64(k / Float64(pi * n)) / 2.0) ^ -0.5 end
function tmp = code(k, n) tmp = ((k / (pi * n)) / 2.0) ^ -0.5; end
code[k_, n_] := N[Power[N[(N[(k / N[(Pi * n), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], -0.5], $MachinePrecision]
\begin{array}{l}
\\
{\left(\frac{\frac{k}{\pi \cdot n}}{2}\right)}^{-0.5}
\end{array}
Initial program 99.2%
Taylor expanded in k around 0
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
PI-lowering-PI.f64N/A
sqrt-lowering-sqrt.f6437.1%
Simplified37.1%
sqrt-unprodN/A
sqrt-lowering-sqrt.f64N/A
clear-numN/A
associate-*l/N/A
metadata-evalN/A
/-lowering-/.f64N/A
*-commutativeN/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
PI-lowering-PI.f6437.2%
Applied egg-rr37.2%
clear-numN/A
inv-powN/A
sqrt-pow1N/A
metadata-evalN/A
metadata-evalN/A
pow-lowering-pow.f64N/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
PI-lowering-PI.f64N/A
metadata-eval38.6%
Applied egg-rr38.6%
(FPCore (k n) :precision binary64 (sqrt (* PI (* n (/ 2.0 k)))))
double code(double k, double n) {
return sqrt((((double) M_PI) * (n * (2.0 / k))));
}
public static double code(double k, double n) {
return Math.sqrt((Math.PI * (n * (2.0 / k))));
}
def code(k, n): return math.sqrt((math.pi * (n * (2.0 / k))))
function code(k, n) return sqrt(Float64(pi * Float64(n * Float64(2.0 / k)))) end
function tmp = code(k, n) tmp = sqrt((pi * (n * (2.0 / k)))); end
code[k_, n_] := N[Sqrt[N[(Pi * N[(n * N[(2.0 / k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\pi \cdot \left(n \cdot \frac{2}{k}\right)}
\end{array}
Initial program 99.2%
Taylor expanded in k around 0
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
PI-lowering-PI.f64N/A
sqrt-lowering-sqrt.f6437.1%
Simplified37.1%
sqrt-unprodN/A
sqrt-lowering-sqrt.f64N/A
clear-numN/A
associate-*l/N/A
metadata-evalN/A
/-lowering-/.f64N/A
*-commutativeN/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
PI-lowering-PI.f6437.2%
Applied egg-rr37.2%
associate-/r/N/A
*-commutativeN/A
associate-*l*N/A
*-lowering-*.f64N/A
PI-lowering-PI.f64N/A
*-lowering-*.f64N/A
/-lowering-/.f6437.2%
Applied egg-rr37.2%
herbie shell --seed 2024145
(FPCore (k n)
:name "Migdal et al, Equation (51)"
:precision binary64
(* (/ 1.0 (sqrt k)) (pow (* (* 2.0 PI) n) (/ (- 1.0 k) 2.0))))