
(FPCore (k n) :precision binary64 (* (/ 1 (sqrt k)) (pow (* (* 2 PI) n) (/ (- 1 k) 2))))
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 / N[Sqrt[k], $MachinePrecision]), $MachinePrecision] * N[Power[N[(N[(2 * Pi), $MachinePrecision] * n), $MachinePrecision], N[(N[(1 - k), $MachinePrecision] / 2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)}
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (k n) :precision binary64 (* (/ 1 (sqrt k)) (pow (* (* 2 PI) n) (/ (- 1 k) 2))))
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 / N[Sqrt[k], $MachinePrecision]), $MachinePrecision] * N[Power[N[(N[(2 * Pi), $MachinePrecision] * n), $MachinePrecision], N[(N[(1 - k), $MachinePrecision] / 2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)}
(FPCore (k n) :precision binary64 (let* ((t_0 (* (+ PI PI) n))) (/ (sqrt t_0) (* (pow t_0 (* 1/2 k)) (sqrt k)))))
double code(double k, double n) {
double t_0 = (((double) M_PI) + ((double) M_PI)) * n;
return sqrt(t_0) / (pow(t_0, (0.5 * k)) * sqrt(k));
}
public static double code(double k, double n) {
double t_0 = (Math.PI + Math.PI) * n;
return Math.sqrt(t_0) / (Math.pow(t_0, (0.5 * k)) * Math.sqrt(k));
}
def code(k, n): t_0 = (math.pi + math.pi) * n return math.sqrt(t_0) / (math.pow(t_0, (0.5 * k)) * math.sqrt(k))
function code(k, n) t_0 = Float64(Float64(pi + pi) * n) return Float64(sqrt(t_0) / Float64((t_0 ^ Float64(0.5 * k)) * sqrt(k))) end
function tmp = code(k, n) t_0 = (pi + pi) * n; tmp = sqrt(t_0) / ((t_0 ^ (0.5 * k)) * sqrt(k)); end
code[k_, n_] := Block[{t$95$0 = N[(N[(Pi + Pi), $MachinePrecision] * n), $MachinePrecision]}, N[(N[Sqrt[t$95$0], $MachinePrecision] / N[(N[Power[t$95$0, N[(1/2 * k), $MachinePrecision]], $MachinePrecision] * N[Sqrt[k], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
t_0 := \left(\pi + \pi\right) \cdot n\\
\frac{\sqrt{t\_0}}{{t\_0}^{\left(\frac{1}{2} \cdot k\right)} \cdot \sqrt{k}}
\end{array}
Initial program 99.5%
lift-pow.f64N/A
lift-/.f64N/A
lift--.f64N/A
div-subN/A
metadata-evalN/A
pow-subN/A
lower-unsound-/.f64N/A
lower-unsound-pow.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-*.f64N/A
count-2-revN/A
lower-+.f64N/A
lower-unsound-pow.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-*.f64N/A
count-2-revN/A
lower-+.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f6499.5%
Applied rewrites99.5%
lift-*.f64N/A
lift-/.f64N/A
lift-/.f64N/A
frac-timesN/A
*-lft-identityN/A
lower-/.f64N/A
lift-pow.f64N/A
unpow1/2N/A
lower-sqrt.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
Applied rewrites99.5%
(FPCore (k n) :precision binary64 (* (pow (* (+ PI PI) n) (* (- 1 k) 1/2)) (sqrt (/ 1 k))))
double code(double k, double n) {
return pow(((((double) M_PI) + ((double) M_PI)) * n), ((1.0 - k) * 0.5)) * sqrt((1.0 / k));
}
public static double code(double k, double n) {
return Math.pow(((Math.PI + Math.PI) * n), ((1.0 - k) * 0.5)) * Math.sqrt((1.0 / k));
}
def code(k, n): return math.pow(((math.pi + math.pi) * n), ((1.0 - k) * 0.5)) * math.sqrt((1.0 / k))
function code(k, n) return Float64((Float64(Float64(pi + pi) * n) ^ Float64(Float64(1.0 - k) * 0.5)) * sqrt(Float64(1.0 / k))) end
function tmp = code(k, n) tmp = (((pi + pi) * n) ^ ((1.0 - k) * 0.5)) * sqrt((1.0 / k)); end
code[k_, n_] := N[(N[Power[N[(N[(Pi + Pi), $MachinePrecision] * n), $MachinePrecision], N[(N[(1 - k), $MachinePrecision] * 1/2), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(1 / k), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
{\left(\left(\pi + \pi\right) \cdot n\right)}^{\left(\left(1 - k\right) \cdot \frac{1}{2}\right)} \cdot \sqrt{\frac{1}{k}}
Initial program 99.5%
lift-pow.f64N/A
lift-/.f64N/A
lift--.f64N/A
div-subN/A
metadata-evalN/A
pow-subN/A
lower-unsound-/.f64N/A
lower-unsound-pow.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-*.f64N/A
count-2-revN/A
lower-+.f64N/A
lower-unsound-pow.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-*.f64N/A
count-2-revN/A
lower-+.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f6499.5%
Applied rewrites99.5%
Applied rewrites99.5%
lift-/.f64N/A
lift-sqrt.f64N/A
metadata-evalN/A
sqrt-fabs-revN/A
lift-sqrt.f64N/A
fabs-divN/A
lift-/.f64N/A
rem-sqrt-square-revN/A
lift-*.f64N/A
lower-sqrt.f6499.4%
lift-*.f64N/A
lift-/.f64N/A
frac-2negN/A
metadata-evalN/A
lift-/.f64N/A
frac-2negN/A
metadata-evalN/A
frac-timesN/A
metadata-evalN/A
sqr-neg-revN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
rem-square-sqrtN/A
lower-/.f6499.5%
Applied rewrites99.5%
(FPCore (k n) :precision binary64 (/ (pow (* n (+ PI PI)) (* 1/2 (- 1 k))) (sqrt k)))
double code(double k, double n) {
return pow((n * (((double) M_PI) + ((double) M_PI))), (0.5 * (1.0 - k))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.pow((n * (Math.PI + Math.PI)), (0.5 * (1.0 - k))) / Math.sqrt(k);
}
def code(k, n): return math.pow((n * (math.pi + math.pi)), (0.5 * (1.0 - k))) / math.sqrt(k)
function code(k, n) return Float64((Float64(n * Float64(pi + pi)) ^ Float64(0.5 * Float64(1.0 - k))) / sqrt(k)) end
function tmp = code(k, n) tmp = ((n * (pi + pi)) ^ (0.5 * (1.0 - k))) / sqrt(k); end
code[k_, n_] := N[(N[Power[N[(n * N[(Pi + Pi), $MachinePrecision]), $MachinePrecision], N[(1/2 * N[(1 - k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\frac{{\left(n \cdot \left(\pi + \pi\right)\right)}^{\left(\frac{1}{2} \cdot \left(1 - k\right)\right)}}{\sqrt{k}}
Initial program 99.5%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
mult-flip-revN/A
lower-/.f6499.5%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.5%
lift-*.f64N/A
count-2-revN/A
lower-+.f6499.5%
lift-/.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f6499.5%
Applied rewrites99.5%
(FPCore (k n)
:precision binary64
(if (<=
k
7482888383134223/748288838313422294120286634350736906063837462003712)
(* (sqrt n) (sqrt (/ (+ PI PI) k)))
(if (<=
k
1949999999999999958289089547254969003180158784162376815230088976785689798552796854866284000535520384908499348776794345879253213054967868666923284326497919619731811089038308278272)
(* n (sqrt (* 2 (/ PI (* k n)))))
(sqrt (* (sqrt (/ (/ 1 k) k)) (* n (+ PI PI)))))))double code(double k, double n) {
double tmp;
if (k <= 1e-35) {
tmp = sqrt(n) * sqrt(((((double) M_PI) + ((double) M_PI)) / k));
} else if (k <= 1.95e+177) {
tmp = n * sqrt((2.0 * (((double) M_PI) / (k * n))));
} else {
tmp = sqrt((sqrt(((1.0 / k) / k)) * (n * (((double) M_PI) + ((double) M_PI)))));
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (k <= 1e-35) {
tmp = Math.sqrt(n) * Math.sqrt(((Math.PI + Math.PI) / k));
} else if (k <= 1.95e+177) {
tmp = n * Math.sqrt((2.0 * (Math.PI / (k * n))));
} else {
tmp = Math.sqrt((Math.sqrt(((1.0 / k) / k)) * (n * (Math.PI + Math.PI))));
}
return tmp;
}
def code(k, n): tmp = 0 if k <= 1e-35: tmp = math.sqrt(n) * math.sqrt(((math.pi + math.pi) / k)) elif k <= 1.95e+177: tmp = n * math.sqrt((2.0 * (math.pi / (k * n)))) else: tmp = math.sqrt((math.sqrt(((1.0 / k) / k)) * (n * (math.pi + math.pi)))) return tmp
function code(k, n) tmp = 0.0 if (k <= 1e-35) tmp = Float64(sqrt(n) * sqrt(Float64(Float64(pi + pi) / k))); elseif (k <= 1.95e+177) tmp = Float64(n * sqrt(Float64(2.0 * Float64(pi / Float64(k * n))))); else tmp = sqrt(Float64(sqrt(Float64(Float64(1.0 / k) / k)) * Float64(n * Float64(pi + pi)))); end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (k <= 1e-35) tmp = sqrt(n) * sqrt(((pi + pi) / k)); elseif (k <= 1.95e+177) tmp = n * sqrt((2.0 * (pi / (k * n)))); else tmp = sqrt((sqrt(((1.0 / k) / k)) * (n * (pi + pi)))); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 7482888383134223/748288838313422294120286634350736906063837462003712], N[(N[Sqrt[n], $MachinePrecision] * N[Sqrt[N[(N[(Pi + Pi), $MachinePrecision] / k), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[k, 1949999999999999958289089547254969003180158784162376815230088976785689798552796854866284000535520384908499348776794345879253213054967868666923284326497919619731811089038308278272], N[(n * N[Sqrt[N[(2 * N[(Pi / N[(k * n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(N[Sqrt[N[(N[(1 / k), $MachinePrecision] / k), $MachinePrecision]], $MachinePrecision] * N[(n * N[(Pi + Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;k \leq \frac{7482888383134223}{748288838313422294120286634350736906063837462003712}:\\
\;\;\;\;\sqrt{n} \cdot \sqrt{\frac{\pi + \pi}{k}}\\
\mathbf{elif}\;k \leq 1949999999999999958289089547254969003180158784162376815230088976785689798552796854866284000535520384908499348776794345879253213054967868666923284326497919619731811089038308278272:\\
\;\;\;\;n \cdot \sqrt{2 \cdot \frac{\pi}{k \cdot n}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\sqrt{\frac{\frac{1}{k}}{k}} \cdot \left(n \cdot \left(\pi + \pi\right)\right)}\\
\end{array}
if k < 1e-35Initial program 99.5%
Taylor expanded in k around 0
lower-/.f64N/A
lower-pow.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f64N/A
lower-sqrt.f6449.5%
Applied rewrites49.5%
lift-/.f64N/A
Applied rewrites38.4%
lift-sqrt.f64N/A
lift-/.f64N/A
mult-flipN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
sqrt-prodN/A
lower-unsound-*.f64N/A
lower-unsound-sqrt.f64N/A
lower-unsound-sqrt.f64N/A
mult-flip-revN/A
lower-/.f6449.4%
Applied rewrites49.4%
if 1e-35 < k < 1.95e177Initial program 99.5%
Taylor expanded in k around 0
lower-/.f64N/A
lower-pow.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f64N/A
lower-sqrt.f6449.5%
Applied rewrites49.5%
lift-/.f64N/A
Applied rewrites38.4%
Taylor expanded in n around inf
lower-*.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-PI.f64N/A
lower-*.f6449.1%
Applied rewrites49.1%
if 1.95e177 < k Initial program 99.5%
Taylor expanded in k around 0
lower-/.f64N/A
lower-pow.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f64N/A
lower-sqrt.f6449.5%
Applied rewrites49.5%
lift-/.f64N/A
Applied rewrites38.4%
rem-square-sqrtN/A
lift-/.f64N/A
sqrt-undivN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
lift-/.f64N/A
sqrt-undivN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
div-flip-revN/A
associate-/r/N/A
lift-sqrt.f64N/A
div-flip-revN/A
Applied rewrites38.3%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
*-rgt-identityN/A
lift-/.f64N/A
lift-sqrt.f64N/A
metadata-evalN/A
sqrt-fabs-revN/A
lift-sqrt.f64N/A
fabs-divN/A
lift-/.f64N/A
rem-sqrt-square-revN/A
lift-*.f64N/A
lift-sqrt.f64N/A
sqrt-undivN/A
lower-sqrt.f64N/A
lower-/.f6434.5%
Applied rewrites34.5%
(FPCore (k n) :precision binary64 (if (<= n 9999999999999999455752309870428160) (sqrt (* (/ (+ PI PI) k) n)) (* n (sqrt (* 2 (/ PI (* k n)))))))
double code(double k, double n) {
double tmp;
if (n <= 1e+34) {
tmp = sqrt((((((double) M_PI) + ((double) M_PI)) / k) * n));
} else {
tmp = n * sqrt((2.0 * (((double) M_PI) / (k * n))));
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (n <= 1e+34) {
tmp = Math.sqrt((((Math.PI + Math.PI) / k) * n));
} else {
tmp = n * Math.sqrt((2.0 * (Math.PI / (k * n))));
}
return tmp;
}
def code(k, n): tmp = 0 if n <= 1e+34: tmp = math.sqrt((((math.pi + math.pi) / k) * n)) else: tmp = n * math.sqrt((2.0 * (math.pi / (k * n)))) return tmp
function code(k, n) tmp = 0.0 if (n <= 1e+34) tmp = sqrt(Float64(Float64(Float64(pi + pi) / k) * n)); else tmp = Float64(n * sqrt(Float64(2.0 * Float64(pi / Float64(k * n))))); end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (n <= 1e+34) tmp = sqrt((((pi + pi) / k) * n)); else tmp = n * sqrt((2.0 * (pi / (k * n)))); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[n, 9999999999999999455752309870428160], N[Sqrt[N[(N[(N[(Pi + Pi), $MachinePrecision] / k), $MachinePrecision] * n), $MachinePrecision]], $MachinePrecision], N[(n * N[Sqrt[N[(2 * N[(Pi / N[(k * n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;n \leq 9999999999999999455752309870428160:\\
\;\;\;\;\sqrt{\frac{\pi + \pi}{k} \cdot n}\\
\mathbf{else}:\\
\;\;\;\;n \cdot \sqrt{2 \cdot \frac{\pi}{k \cdot n}}\\
\end{array}
if n < 9.9999999999999995e33Initial program 99.5%
Taylor expanded in k around 0
lower-/.f64N/A
lower-pow.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f64N/A
lower-sqrt.f6449.5%
Applied rewrites49.5%
lift-/.f64N/A
Applied rewrites38.4%
lift-/.f64N/A
mult-flipN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
mult-flip-revN/A
lower-/.f6438.4%
Applied rewrites38.4%
if 9.9999999999999995e33 < n Initial program 99.5%
Taylor expanded in k around 0
lower-/.f64N/A
lower-pow.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f64N/A
lower-sqrt.f6449.5%
Applied rewrites49.5%
lift-/.f64N/A
Applied rewrites38.4%
Taylor expanded in n around inf
lower-*.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-PI.f64N/A
lower-*.f6449.1%
Applied rewrites49.1%
(FPCore (k n) :precision binary64 (sqrt (* (/ (+ PI PI) k) n)))
double code(double k, double n) {
return sqrt((((((double) M_PI) + ((double) M_PI)) / k) * n));
}
public static double code(double k, double n) {
return Math.sqrt((((Math.PI + Math.PI) / k) * n));
}
def code(k, n): return math.sqrt((((math.pi + math.pi) / k) * n))
function code(k, n) return sqrt(Float64(Float64(Float64(pi + pi) / k) * n)) end
function tmp = code(k, n) tmp = sqrt((((pi + pi) / k) * n)); end
code[k_, n_] := N[Sqrt[N[(N[(N[(Pi + Pi), $MachinePrecision] / k), $MachinePrecision] * n), $MachinePrecision]], $MachinePrecision]
\sqrt{\frac{\pi + \pi}{k} \cdot n}
Initial program 99.5%
Taylor expanded in k around 0
lower-/.f64N/A
lower-pow.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f64N/A
lower-sqrt.f6449.5%
Applied rewrites49.5%
lift-/.f64N/A
Applied rewrites38.4%
lift-/.f64N/A
mult-flipN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
mult-flip-revN/A
lower-/.f6438.4%
Applied rewrites38.4%
(FPCore (k n) :precision binary64 (sqrt (* (/ n k) (+ PI PI))))
double code(double k, double n) {
return sqrt(((n / k) * (((double) M_PI) + ((double) M_PI))));
}
public static double code(double k, double n) {
return Math.sqrt(((n / k) * (Math.PI + Math.PI)));
}
def code(k, n): return math.sqrt(((n / k) * (math.pi + math.pi)))
function code(k, n) return sqrt(Float64(Float64(n / k) * Float64(pi + pi))) end
function tmp = code(k, n) tmp = sqrt(((n / k) * (pi + pi))); end
code[k_, n_] := N[Sqrt[N[(N[(n / k), $MachinePrecision] * N[(Pi + Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\sqrt{\frac{n}{k} \cdot \left(\pi + \pi\right)}
Initial program 99.5%
Taylor expanded in k around 0
lower-/.f64N/A
lower-pow.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f64N/A
lower-sqrt.f6449.5%
Applied rewrites49.5%
lift-/.f64N/A
Applied rewrites38.4%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6438.4%
Applied rewrites38.4%
herbie shell --seed 2025271 -o generate:evaluate
(FPCore (k n)
:name "Migdal et al, Equation (51)"
:precision binary64
(* (/ 1 (sqrt k)) (pow (* (* 2 PI) n) (/ (- 1 k) 2))))