Skip to main content

list manipulation - Approximating the density of $Scap[a,b]$ using a Folner Sequence of $A$, where $S subseteq A$?


Edit: I redid my code but it's still not working.


How do we use Mathematica to approximate


$$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$) and here.


$A$ is countable and dense in $\mathbb{R}$ and can be written as the operations of finite or infinite one-variable functions that, when defined on countable domains dense in $\mathbb{R}$, intersect with the integers.


Example:


$$A=\left\{\frac{m+\ln(w)}{2^{(p/q)}+\sqrt{z}}:m,p,q,z,w\in\mathbb{Z},2^{p/q}+\sqrt{z}\neq0,q\neq0,z>0,w>0\right\}$$



There are many Folner Sequence of $A$. In general, the most natural, "intuitive" sequence is calculated by restricting the whole set, and the variables of each function in the set, by $n$.


$$F_n=\left\{\frac{m+\ln(w)}{2^{(p/q)}+\sqrt{z}}:m,p,q,z\in\mathbb{Z},2^{p/q}+\sqrt{z}\neq0,q\neq0,z>0, w>0,\left|\frac{m+\ln(w)}{2^{(p/q)}+\sqrt{z}}\right|\le n,|m|\le n,|p|\le n,|q|\le n, |z| \le n, |w| \le n\right\}$$


$S$ can be written similarly to $A$ except it must be a subset.


Example:


$$S=\left\{\frac{m_1}{2^{(p_1/q_1)}+\sqrt{z_1}}:m_1,q_1,z_1\in\mathbb{Z},2^{(p_1/q_1)}+\sqrt{z_1}\neq0,q_1\neq0,z_1>0\right\}$$


I attempted to approximate $D(S\cap[0,1])$ when $S=\left\{\frac{m^2}{n^2}:m,n\in\mathbb{Z},n\neq 0\right\}$, $A=\mathbb{Q}$, $F_n=\left\{\frac{p}{2^k(2q+1)}:p,k,q\in\mathbb{Z},2^k \le n, |2q+1|\le n, \left|\frac{p}{2^k(2q+1)}\right|\le n\right\}$.


(In my code I replaced $A$ with A[x_,y_,z_,...] and $F_n$ with F[x_,y_,z_,...], $S$ with S[x_,y_,z_,...], and $D$ with d. I also set $a=0$ and $b=1$.)


I tried to list all elements of $F_n\cap[0,1]$ depending on $n$ and determine which elements in $S\cap[0,1]$ exist in $F_n\cap[0,1]$. Then I counted all elements where this holds and divided it by the total elements in $F_n\cap[0,1]$.


Unprotect[d]
Remove[d]

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}]]]
S[j_, k_] := j^2/k^2
X[a_, b_, n_] :=
Count[Boole[Resolve[Exists[{j, k}, S[j, k] == Ff[n, a, b]]]], 1]
Y[a_, b_, n_] := Count[Ff[n, a, b]]
d[n_, a_, b_] := N[(Y[a, b, S] - X[a, b, S])/Y[a, b, S]]
Ff[4, 1, 2]
X[1, 2, 4]
Y[1, 2, 4]

d[1, 2, 4]

Instead, I get


 During evaluation of In[629]:= Table::iterb: Iterator {v,1,1+Floor[Log[S]/Log[2]]} does not have appropriate bounds.

During evaluation of In[629]:= Table::iterb: Iterator {v,1,1+Floor[Log[S]/Log[2]]} does not have appropriate bounds.

During evaluation of In[629]:= Table::iterb: Iterator {v,1,1+Floor[Log[S]/Log[2]]} does not have appropriate bounds.

During evaluation of In[629]:= General::stop: Further output of Table::iterb will be suppressed during this calculation.


During evaluation of In[629]:= Exists::msgs: Evaluation of S[j,k]==Ff[S,2,4] generated message(s) {General::stop,Table::iterb}.

During evaluation of In[629]:= Exists::msgs: Evaluation of j^2/k^2==Table[F[f[<<3>>][[v]][[u]],S][[v]][[u]],{v,1,1+Floor[Log[S]/Log[<<1>>]]},{u,1,Floor[(S-1)/2]+1}] generated message(s) {Table::iterb}.

During evaluation of In[629]:= Exists::msgs: Evaluation of j^2/k^2==Table[F[f[<<3>>][[v]][[u]],S][[v]][[u]],{v,1,1+Floor[Log[S]/Log[<<1>>]]},{u,1,Floor[(S-1)/2]+1}] generated message(s) {Table::iterb}.

During evaluation of In[629]:= General::stop: Further output of Exists::msgs will be suppressed during this calculation.

Out[642]= 1.


Is there a better and faster method to solving my example? How do we generalize this for any $S\cap[a,b]$ and $A\cap[a,b]$?



Answer



This works and provides expected resulst as far as I'm aware:


Clear[A, F, f, p, Ff, S, X, Y, d, j, k];
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}
];
S[j_, k_] := j^2/k^2;
X[n_, a_, b_] :=

Count[Resolve[
Exists[{j, k}, S[j, k] == # && {j, k} ∈ Integers]] & /@
Ff[n, a, b], True];
Y[n_, a_, b_] := Length[Ff[n, a, b]];
d[n_, a_, b_] := N[(Y[n, a, b] - X[n, a, b])/Y[n, a, b]];
Ff[4, 1, 2]
X[4, 1, 2]
Y[4, 1, 2]
d[4, 1, 2]



{1,2,4/3,5/3,3/2,7/6,11/6,5/4,7/4,13/12,17/12,19/12,23/12}
1
13
0.923077



Comments

Popular posts from this blog

plotting - Filling between two spheres in SphericalPlot3D

Manipulate[ SphericalPlot3D[{1, 2 - n}, {θ, 0, Pi}, {ϕ, 0, 1.5 Pi}, Mesh -> None, PlotPoints -> 15, PlotRange -> {-2.2, 2.2}], {n, 0, 1}] I cant' seem to be able to make a filling between two spheres. I've already tried the obvious Filling -> {1 -> {2}} but Mathematica doesn't seem to like that option. Is there any easy way around this or ... Answer There is no built-in filling in SphericalPlot3D . One option is to use ParametricPlot3D to draw the surfaces between the two shells: Manipulate[ Show[SphericalPlot3D[{1, 2 - n}, {θ, 0, Pi}, {ϕ, 0, 1.5 Pi}, PlotPoints -> 15, PlotRange -> {-2.2, 2.2}], ParametricPlot3D[{ r {Sin[t] Cos[1.5 Pi], Sin[t] Sin[1.5 Pi], Cos[t]}, r {Sin[t] Cos[0 Pi], Sin[t] Sin[0 Pi], Cos[t]}}, {r, 1, 2 - n}, {t, 0, Pi}, PlotStyle -> Yellow, Mesh -> {2, 15}]], {n, 0, 1}]

plotting - Plot 4D data with color as 4th dimension

I have a list of 4D data (x position, y position, amplitude, wavelength). I want to plot x, y, and amplitude on a 3D plot and have the color of the points correspond to the wavelength. I have seen many examples using functions to define color but my wavelength cannot be expressed by an analytic function. Is there a simple way to do this? Answer Here a another possible way to visualize 4D data: data = Flatten[Table[{x, y, x^2 + y^2, Sin[x - y]}, {x, -Pi, Pi,Pi/10}, {y,-Pi,Pi, Pi/10}], 1]; You can use the function Point along with VertexColors . Now the points are places using the first three elements and the color is determined by the fourth. In this case I used Hue, but you can use whatever you prefer. Graphics3D[ Point[data[[All, 1 ;; 3]], VertexColors -> Hue /@ data[[All, 4]]], Axes -> True, BoxRatios -> {1, 1, 1/GoldenRatio}]

plotting - Mathematica: 3D plot based on combined 2D graphs

I have several sigmoidal fits to 3 different datasets, with mean fit predictions plus the 95% confidence limits (not symmetrical around the mean) and the actual data. I would now like to show these different 2D plots projected in 3D as in but then using proper perspective. In the link here they give some solutions to combine the plots using isometric perspective, but I would like to use proper 3 point perspective. Any thoughts? Also any way to show the mean points per time point for each series plus or minus the standard error on the mean would be cool too, either using points+vertical bars, or using spheres plus tubes. Below are some test data and the fit function I am using. Note that I am working on a logit(proportion) scale and that the final vertical scale is Log10(percentage). (* some test data *) data = Table[Null, {i, 4}]; data[[1]] = {{1, -5.8}, {2, -5.4}, {3, -0.8}, {4, -0.2}, {5, 4.6}, {1, -6.4}, {2, -5.6}, {3, -0.7}, {4, 0.04}, {5, 1.0}, {1, -6.8}, {2, -4.7}, {3, -1.