# Approximating the density of an arbitrary set using an arbitrary Folner Sequence of its superset [duplicate]

How do we use Programming to approximate this limit

where is the density of in , is the Folner Sequence of , is an interval with , and . For more information, click on this link (replace G,X,i,g with A,S,n,a) and click here.

is countable and dense in and can be written as the operations and compositions of finite or infinite one-variable functions that, when defined on countable domains dense in , intersect with the integers.

Example:

There are many Folner Sequence of . In general, the most natural, "intuitive" sequence is calculated by restricting the variables of each function by .

can be written similarly to except it must be a subset of .

Example:

Here was my attempt for approximating when , and

(In my code I replaced with A[x_,y_,z_,...] and with F[x_,y_,z_,...], with S[x_,y_,z_,...] ) and with D (I forgot D was a built in function).

Using Mathematica, I tried to list all elements of depending on and determine which elements in exist in . Then I counted all elements in and divided it by the total elements in .

Unprotect[a, b, p, k, q, g, G, i, s, O, D, X, Y, TT, S]
Remove[a, b, p, k, q, g, G, i, s, O, D, X, Y, TT, S]
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]}]
G[p_, n_] := Flatten[F[p, n]]
a = 1
b = 2
i[s_] := Solve[s > a && s < b, p, Integers]
T[l_, n_] := Thread[G[l, n], n]
TT[n_] := DeleteDuplicates[Flatten[T[O[n], n]]]
S[j_, k_] := j^2/k^2
X[n_] = Count[Boole[Resolve[Exists[{j, k}, S[j, k] == TT[n]]]], 1]
Y[n_] = Count[TT[n]]
D[S_] := N[X[S]/Y[S]]
D[100]


{}
1
2
Exists::msgs
Exists::msgs
Exists::msgs
General::stop
0
Solve::nsmet
Count[g[Solve[g[p, n] > 1 && g[p, n] < 2, p, Integers], n]]
Solve::nsmet
0.


Is there a better and faster method to solving my example? How do we generalize this for any and ?