# Correctly Evaluating the existence of Large Solutions

I'm trying to correctly evaluate

$$D(S\cap[a,b])=\lim_{n\to\infty}\frac{\left|S\cap{F_n\cap[a,b]}\right|}{\left|F_n\cap[a,b]\right|}$$

where $$D$$ is the density of $$S\cap[a,b]$$ (in $$A\cap[a,b]$$), $$[a,b]$$ is an interval for $$a,b\in\mathbb{R}$$, $$F_n$$ is the Folner Sequence of $$A$$, and $$S\subseteq A$$. For more information, click here (replace $$G,X,i,g$$ with $$A,S,n,a$$), click (here) and here.

I set $$A=\left\{\frac{p}{2^k(2q+1)}:p,q,k\in\mathbb{Z},k\ge 0\right\}$$, $$F_n=\left\{\frac{p}{2^k(2q+1)}:p,q,k\in\mathbb{Z},k\le n,|2q+1|\le n\right\}$$ and $$S=\left\{\frac{j^2}{k^3}:j,k\in\mathbb{Z},k\neq 0\right\}$$

In my code $$A$$ is A[p_,k_,q_], $$F_n$$ is f[n_,a_,b_], $$S$$ is S[j_,k_] and $$D$$ is d.

Clear[A, F, f, p, Ff, S, X, Y, d, j, k, q, n, a, b];
A[p_, k_, q_] := p/((2^k)*(2*q + 1));
F[p_, n_] :=
Table[A[p, k, q], {k, 0, Floor[Log[2, n]]}, {q, 0,
Floor[(n - 1)/2]}];
f[n_, a_, b_] :=
p /. Table[
Solve[a <= A[p, k, q] <= b, p, Integers], {k, 0,
Floor[Log[2, n]]}, {q, 0, Floor[(n - 1)/2]}];
Ff[n_, a_, b_] :=
DeleteDuplicates@
Flatten@Table[
F[f[n, a, b][[v]][[u]], n][[v]][[u]], {v, 1,
Floor[Log[2, n]] + 1}, {u, 1, Floor[(n - 1)/2] + 1}];
RandomsampleFf[n_, a_, b_] := RandomSample[Ff[n, a, b], 100]
S[j_, k_] := (j^2)/(k^3);
X[n_, a_, b_] :=
Count[Resolve[
Exists[{j, k}, S[j, k] == # && {j, k} \[Element] Integers]] & /@
RandomsampleFf[n, a, b], True];
Y[n_, a_, b_] := Length[RandomsampleFf[n, a, b]];
d[n_, a_, b_] := N[(X[n, a, b])/Y[n, a, b]];
RandomsampleFf[40, 1, 2]
Num = X[40, 1, 2]
Den = Y[40, 1, 2]
Timing[N[Num/Den]]


My result is

{2329/1184, 1571/992, 719/432, 783/608, 325/272, 557/304, 1375/992, \
403/240, 1779/1120, 1767/1184, 2355/1184, 103/72, 1821/992, 867/800, \
505/464, 581/544, 365/312, 23/12, 947/608, 1735/1184, 1907/1120, \
335/288, 229/184, 1243/736, 1163/672, 67/50, 1487/1248, 377/280, \
15/8, 1999/1184, 379/200, 809/416, 859/496, 1569/1120, 569/544, \
1841/928, 1469/864, 101/88, 355/336, 631/416, 907/480, 607/312, \
341/296, 66/35, 531/352, 257/160, 619/400, 467/248, 1659/928, \
213/200, 573/560, 283/224, 493/336, 273/232, 1873/1248, 305/216, \
1005/928, 1059/992, 597/352, 61/38, 137/76, 203/132, 825/736, \
761/736, 57/52, 583/432, 1123/624, 195/124, 779/464, 223/140, \
1611/1120, 939/800, 261/248, 891/736, 329/232, 1343/1184, 2073/1184, \
225/208, 785/608, 521/432, 707/464, 477/248, 38/23, 543/272, 171/104, \
519/280, 1071/800, 1487/800, 557/352, 811/528, 677/432, 85/48, \
1295/1248, 379/224, 1559/928, 1483/864, 72/37, 403/216, 71/36, 231/136}
4
100
{0., 0.04}


The Density is 0.04 instead of 1. This is because Exists incorrectly evaluates existence of larger elements in RandomSampleFf[n,a,b]. How do we correct Exists if the values of RandomSampleFf[n,a,b] are arbitrary.