How can I calculate x/log(x) = y for a given y?

85 Views Asked by At

I try to test a random prime number generator with a chi-square-test. The prime number generator should generate some prime numbers randomly between [x,y]. But I guess, that the distance between two classes of the chi-square-test would not be correct, if I try to classify with (y/log(y)-x/log(x))/"NUMBER_OF_CLASSES".

My approach will be, that I calculate the number of primes between x and y. Then calculate the number of primes in each class with y' = "NUMBER_OF_PRIMES/NUMBER_OF_CLASSES", and next I will get the distance for each class with x/log(x) = y'.

But how can I calculate x/log(x) = y', for example: x/log(x) = 10.000?

thx

1

There are 1 best solutions below

0
On

The anlytical solution of $$\frac x{\log(x)}=y$$ is given in terms of Lambert function and $x$ is given by $$x=-y \,W_{-1}\left(-\frac{1}{y}\right)$$ Since, in your case, $y$ is large, the argument of Lambert function is small and you can approximate it $$W(t)=L_1-L_2+\frac{L_2}{L_1}+\frac{L_2(L_2-2)}{2L_1^2}+\frac{L_2(6-9L_2+2L_2^2)}{6L_1^3}+\cdots$$ where $L_1=\log(-t)$ and $L_2=\log(-L_1)$ (a given in the linked page).

Since you are concerned by large values of $y$, let $y=10^k$. The table below reproduces the approximated values as well as the exact values for a few $k$ $$\left( \begin{array}{ccc} k & \text{approximation} & \text{exact} \\ 1 & 35.8923 & 35.7715 \\ 2 & 647.297 & 647.278 \\ 3 & 9117.71 & 9118.01 \\ 4 & 116669. & 116671. \\ 5 & 1.41635\times 10^6 & 1.41636\times 10^6 \\ 6 & 1.66264\times 10^7 & 1.66265\times 10^7 \\ 7 & 1.90659\times 10^8 & 1.90660\times 10^8 \\ 8 & 2.14881\times 10^9 & 2.14882\times 10^9 \\ 9 & 2.38970\times 10^{10} & 2.38970\times 10^{10} \\ 10 & 2.62952\times 10^{11} & 2.62952\times 10^{11} \end{array} \right)$$

If you do not want to use Lambert function, consier that you look for the zero of function $$f(x)=x-y \log(x)$$ and use Newton method with $x_0=y \log(y)$ as a starting point. For $y=10^4$, the iterates would be $$\left( \begin{array}{cc} n & x_n \\ 0 & 92103.40372 \\ 1 & 117010.9772 \\ 2 & 116671.1915 \\ 3 & 116671.1453 \end{array} \right)$$ which is the solution for ten significant figures. You could make it even faster using Halley or Householder methods.

If you are not too requiring, the first iteration of Halley method will give $$x=\frac{y \log (y) (-3 \log (y)+(2 \log (y)-1) \log (y \log (y))+2)}{\log (y) (2 \log (y)-5)+\log (y \log (y))+2}$$ which, for $y=10^4$, would give $x\approx 116607.4230$.