An integer $n$ is said to be square-free, if it is not divisible by any perfect square other than $1$. That is, each prime that appears in its prime factorisation is raised to the power of one.
So, for example, $6$ is square free but $27$ is not since it is divisble by $3^2$.
Let's consider, the probabilties of choosing integers randomly. In general, the probability of a number being divisible by $n$ is $\frac{1}{n}$. This is because a multiple of $n$ comes every $n$ numbers. Of course, in this we are assuming that each number is equally likely to be chosen, which is reasonable.
Now, consider the famous standard result A.K.A. the Basel problem:
Let $S=\sum_{i=1}^{\infty}\frac{1}{i^2}=\frac{1}{1^2}+\frac{1}{2^2}+\frac{1}{3^2}+\dots$ Since we are trying to involve $\left(1-\frac{1}{{p_k}^2}\right)$ into our calculations, we will do the following:
Notice how we have now removed all fractions with multiples of $2$ in their denominator from the RHS of the equation above. We will continue in this way.
So all fractions which have denominators with factors of 2 and 3 are now removed from the RHS. We can carry on for all primes, removing all the numbers from the RHS, until we are only left with 1.
Thus, we have demonstrated that $P($all primes $p^2$ do not divide $x)=\frac{6}{\pi^2}$ i.e. the probability of a positive integer being square free is $\frac{6}{\pi^2}$ !
We can confirm the validity of this elegant result iteratively through a Python algorithm. The following code defines a function isSquareFree to determine whether a given number is square-free or not.Note that the for loop above the function definition is used for the iteration later on.
b=np.array([])
for k in range(0,100):
def isSquareFree(n):
if n % 2 == 0:
n = n / 2
if n % 2 == 0:
return False
for i in range(3, int(np.sqrt(n) + 1)):
if n % i == 0:
n = n / i
if n % i == 0:
return False
return True
We then define an array $a$, which contains 10000 ranomdly generated integers between 0 and 1000. From this, we determine the proportion of numbers which are square-free and store this in $b$, previously defined.
a=np.random.randint(1000,size=10000)
count=0
for i in range(0, len(a)):
if isSquareFree(a[i]) == True:
count=count+1
x = count/len(a)
b = np.append(b,x)
As this whole process is repeated 100 times (see the second line of code in the first code block above), the array $b$ contains 100 elements of proportions from 100 different sets of 10000 numbers.
We can output this data in various formats; for instance, we can print the array $b$ and work out its mean.
Observe how extremely close the mean value computed above is to the true value of $\frac{6}{\pi^2}$. We can also graph all the iterations:
── KN7811 ──