Skip to main content

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


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


How do we use Mathematica to approximate


D(S∩[a,b])=limn→∞|S∩Fn∩[a,b]||Fn∩[a,b]|


where D is the density of S∩[a,b] (in A∩[a,b]), [a,b] is an interval for a,b∈R, Fn is the Folner Sequence of A, and S⊆A. For more information, click here (replace G,X,i,g with A,S,n,a) and here.


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


Example:


A={m+ln(w)2(p/q)+√z:m,p,q,z,w∈Z,2p/q+√z≠0,q≠0,z>0,w>0}



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.


Fn={m+ln(w)2(p/q)+√z:m,p,q,z∈Z,2p/q+√z≠0,q≠0,z>0,w>0,|m+ln(w)2(p/q)+√z|≤n,|m|≤n,|p|≤n,|q|≤n,|z|≤n,|w|≤n}


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


Example:


S={m12(p1/q1)+√z1:m1,q1,z1∈Z,2(p1/q1)+√z1≠0,q1≠0,z1>0}


I attempted to approximate D(S∩[0,1]) when S={m2n2:m,n∈Z,n≠0}, A=Q, Fn={p2k(2q+1):p,k,q∈Z,2k≤n,|2q+1|≤n,|p2k(2q+1)|≤n}.


(In my code I replaced A with A[x_,y_,z_,...] and Fn 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 Fn∩[0,1] depending on n and determine which elements in S∩[0,1] exist in Fn∩[0,1]. Then I counted all elements where this holds and divided it by the total elements in Fn∩[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∩[a,b] and A∩[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

functions - Get leading series expansion term?

Given a function f[x] , I would like to have a function leadingSeries that returns just the leading term in the series around x=0 . For example: leadingSeries[(1/x + 2)/(4 + 1/x^2 + x)] x and leadingSeries[(1/x + 2 + (1 - 1/x^3)/4)/(4 + x)] -(1/(16 x^3)) Is there such a function in Mathematica? Or maybe one can implement it efficiently? EDIT I finally went with the following implementation, based on Carl Woll 's answer: lds[ex_,x_]:=( (ex/.x->(x+O[x]^2))/.SeriesData[U_,Z_,L_List,Mi_,Ma_,De_]:>SeriesData[U,Z,{L[[1]]},Mi,Mi+1,De]//Quiet//Normal) The advantage is, that this one also properly works with functions whose leading term is a constant: lds[Exp[x],x] 1 Answer Update 1 Updated to eliminate SeriesData and to not return additional terms Perhaps you could use: leadingSeries[expr_, x_] := Normal[expr /. x->(x+O[x]^2) /. a_List :> Take[a, 1]] Then for your examples: leadingSeries[(1/x + 2)/(4 + 1/x^2 + x), x] leadingSeries[Exp[x], x] leadingSeries[(1/x + 2 + (1 - 1/x...

mathematical optimization - Minimizing using indices, error: Part::pkspec1: The expression cannot be used as a part specification

I want to use Minimize where the variables to minimize are indices pointing into an array. Here a MWE that hopefully shows what my problem is. vars = u@# & /@ Range[3]; cons = Flatten@ { Table[(u[j] != #) & /@ vars[[j + 1 ;; -1]], {j, 1, 3 - 1}], 1 vec1 = {1, 2, 3}; vec2 = {1, 2, 3}; Minimize[{Total@((vec1[[#]] - vec2[[u[#]]])^2 & /@ Range[1, 3]), cons}, vars, Integers] The error I get: Part::pkspec1: The expression u[1] cannot be used as a part specification. >> Answer Ok, it seems that one can get around Mathematica trying to evaluate vec2[[u[1]]] too early by using the function Indexed[vec2,u[1]] . The working MWE would then look like the following: vars = u@# & /@ Range[3]; cons = Flatten@{ Table[(u[j] != #) & /@ vars[[j + 1 ;; -1]], {j, 1, 3 - 1}], 1 vec1 = {1, 2, 3}; vec2 = {1, 2, 3}; NMinimize[ {Total@((vec1[[#]] - Indexed[vec2, u[#]])^2 & /@ R...

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}]