Calculating the floor of \(y^{1/m}\)


Abstract

We present two algorithms based on the Newton-Raphson method to calculate \(\lfloor y^{1/m} \rfloor\) for natural integer numbers \(y>2\) and \(m >1\). One could use such an algorithm to establish whether \(y\) is an integer power of an integer in number theory problems, even though binary search methods are traditionally considered simpler to implement.

1 Introduction↩︎

In several number theory algorithms we would like to determine whether natural number \(y\) is a perfect power that is, there exist two natural numbers \(x\) and \(m>1\) such that \(y= x^m\). The primality testing algorithms of Miller [1] [2] and AKS primality testing [3] utilize such an identification method in the introductory steps of those algorithms. The traditional approach to find \(x,m\) is to use binary search. For \(y=x^m\) and \(m>1\) implies \(y=x^m \geq 2^m\) and therefore \(m \leq \lg{y}\). Therefore one tests for each integer \(m\) between integer two and the integer closer to \(\lg{y}\) (or the floor of it) whether there exists an integer \(x\) such that \(y=x^m\) by performing a binary search of \(x\) on the integer interval between two and \(y\). The exponentiation algorithm with repeated doubling can calculate \(x^m\) efficiently within the efficiency requirements of those two algorithms. Furthermore, one need only search for prime numbers \(m\) in the given range and by doing so one can further optimize the running time of the approach. In general the running time for perfect power identification contributes low order terms to the overall running time either of Miller’s primality testing algorithms, or the AKS algorithm. The binary search-based method is not computationally efficient in the bit model of computation, where bit-based arithmetic computations are used to express the arithmetic complexity of an algorithm. Yet it is quite practical.

It is known that other methods can be used to solve the perfect power identification problem as implied in [4] (page 59). For example, Newton-Raphson based methods have been used to determine the \(m\)-th root \(\sqrt[m]{y}\) of an arbitrary real number \(y\). We utilize such a method to calculate \(\lfloor y^{1/m} \rfloor\). In fact we present two different algorithms: they differ only on the way they derive an integer-based version of Newton-Raphson. Having computed \(Y=\lfloor y^{1/m} \rfloor\) one needs only test whether \(Y^m = y\) to determine not only whether \(y\) is a perfect power but calculate \(x=Y\).

Such techniques using Newton-Raphson for integers problems are not new e.g. see [4]. Our intent is just to provide an archival reference to such methods rather than making claims on their novelty.

2 First approach↩︎

The first approach is a quite straightforward adaptation of a real number Newton-Raphson method for calculating \(y^{\frac{1}{m}}\). It is modified into an integer-based Newton-Raphson method for calculating \(\left\lfloor y^{\frac{1}{m}} \right\rfloor\). We call this approach Algorithm 1. It is subsequently modified and refined into what we call Algorithm 2.

Lemma 1. Given a natural integer number \(y>2\) and a natural integer number \(m>1\), Algorithm 1 determines a natural integer number \(x\) such that \[x = \left\lfloor y^{\frac{1}{m}} \right\rfloor .\]

Proof. \(None\)
\(None\) In the remainder, \(\lg{y}\) denotes the logarithm of \(y\) base two. We are going to use the following inequalities related to the floor and ceiling functions. \[\label{pp1a} x-1 < \lfloor x \rfloor \leq x \leq \lceil x \rceil < x+1 .\tag{1}\] \[\label{pp1b} 1+ \lfloor x \rfloor \geq \lceil x \rceil .\tag{2}\] \(None\)
\(None\) The symbol \(\lfloor < 0 \rfloor\) will denote a negative quantity. The symbol \(\lceil >0 \rceil\) will denote a positive quantity. In either case we are only interested in the sign, but not the quantity itself. The Newton-Raphson method is highlighted below. For more information see for example [5]. \(None\)
\(None\) (a) Newton-Raphson iterative method: an overview. \(None\)
\(None\) Given \(f(x)\) in Eq.(3 ) that follow, \[\label{pp2} f(x) = y - x^m ,\tag{3}\] its solution for \(f(x)=0\) is \(x = y^{1/m}\). Let \(Y= y^{1/m}\). Moreover we derive that \(f^\prime (x) = - m x^{m-1}\). Let us then use the Newton-Raphson iterative method, where \(y^{1/m} = Y\) implies \(y = Y^m\) as follows. \[\begin{align} \label{pp3} x_{i+1} &=& x_{i} - \frac{f(x_i ) }{ f^\prime (x_i )} \nonumber \\ &=& x_i + \frac{y-x_i^m}{m \cdot x_i^{m-1}} = x_i + \frac{Y^m -x_i^m}{m \cdot x_i^{m-1}}, \end{align}\tag{4}\] for \(i \geq 0\). The initial condition \(x_0\) will be determined and described later. \(None\)
\(None\) (b) Integer Newton-Raphson. \(None\)
\(None\) In order to obtain an integer approximation, we modify Eq.(4 ) so that we get integer values at various iterations. \[\begin{align} x_{i+1} &=& \label{pp4} x_i + \left\lfloor \frac{y-x_i^m}{m \cdot x_i^{m-1}} \right\rfloor = x_i + \left\lfloor \frac{Y^m -x_i^m}{m \cdot x_i^{m-1}} \right\rfloor . \end{align}\tag{5}\] The numerator and denominator of the fraction are integer numbers, so the fraction becomes the integer quotient of a long integer division. If \(x_0\) the sequence generated of \(x_0 , x_1 , \ldots\) is an integer sequence. \(None\)
\(None\) (c) Choice of the initial value \(x_0\). \(None\)
\(None\) The integer recurrence relation of Eq.(5 ) provides an integer sequence \(x_0 , x_1 , \ldots\) as long as \(x_0\), the initial condition, is also an integer. We first note the following. \[\begin{align} \label{pp5} 2^{1+ \lfloor \lceil \lg{y} \rceil/m \rfloor} &\geq& 2^{\lceil \lceil \lg{y} \rceil/m \rceil} \geq 2^{\lg{y}/m} = y^{1/m} = Y, \end{align}\tag{6}\] At the same time, \[\begin{align} \label{pp5a} 2^{1+ \lfloor \lceil \lg{y} \rceil/m \rfloor} &\leq& 2 \cdot 2^{\lceil \lg{y} \rceil/m} \leq 4 \cdot 2^{\lg{y}/m} = 4 y^{1/m} = 4Y, \end{align}\tag{7}\] and therefore consider choosing an \(x_0\) such that \[\begin{align} \tag{8} Y= y^{1/m} \leq x_0 \leq 2 \cdot 2^{\lceil \lg{y} \rceil/m} \leq 4 y^{1/m} =4Y \Leftrightarrow\\ \tag{9} \lfloor \lg{y} \rfloor \leq \lg{y} \leq m \cdot \lg{x_0} \leq m + {\lceil \lg{y} \rceil} . \end{align}\] \(None\)
\(None\) Starting with \(y\), finding \(\lceil \lg{y} \rceil\) and \(\lfloor \lg{y} \rfloor\) is easy as it requires shift operations and can be done in \(O(\lg{y})\) shifts. Then by raising integer two to the \(\lfloor \lg{y} \rfloor\)-th power we can verify whether \(\lfloor \lg{y} \rfloor = \lg{y}\) or not. Then, the integer range \([\lg{y} , m + {\lceil \lg{y} \rceil} ]\) contains at least \(m\) consecutive integers and therefore an integer that is a multiple of \(m\). We set that integer multiple of \(m\) to \(m \cdot \lg{x_0}\). By implication \(\lg{x_0}\) and thus \(x_0\) become integer. Then, \(x_0\) still satisfies inequalities Eq.(9 ) and Eq.(8 ). Therefore \(x_0\) is easy to compute and is calculated the way described. \(None\)
\(None\) (d) Iteration \(i=0 \Rightarrow i+1=1\). Consider an \(x_0\) chosen as described in (c) above with \(x_0\) satisfying Eq.(8 ) and Eq.(9 ) that yields \(x_0 \geq y^{1/m} =Y\) and consequently \(x_0^m -y \geq 0\) and \(x_0^m - Y^m \geq 0\) or, \[\begin{align} \label{pp6} y- x_0^m &\leq& 0 \Leftrightarrow Y^m - x_0^m \leq 0 \end{align}\tag{10}\] By Eq.(5 ) because of Eq.(10 ) for \(i=0\) we obtain that \(x_1 = x_0 + \lfloor \leq 0 \rfloor \leq x_0\) as follows. \[\begin{align} \label{pp6a} x_{1} &=& x_0 + \left\lfloor \frac{Y^m -x_0^m}{m \cdot x_0^{m-1}} \right\rfloor = x_0 + \left\lfloor \frac{y-x_0^m}{m \cdot x_0^{m-1}} \right\rfloor \leq x_0 . \end{align}\tag{11}\] Note that the numerator \(Y^m -x_0^m\) in Eq.(11 ) is non-positive by way of \(x_0 \geq y^{1/m} =Y\). If it is zero, then \(Y^m = x_0^m\) and \(x_1 = x_0\), which imply \(x_0 = Y = y^{1/m}\) and since \(x_0\) is an integer we have \(\lfloor y^{1/m} \rfloor = x_0\) and the calculation goes no further. Otherwise, subsequence \(x_0 , x_1\) is a decreasing sequence since \(x_0 \geq x_1\) and it is not \(x_0 = x_1\). Furthermore, because \(x_0 \geq Y\), we have the following, \[\begin{align} x_0^m - y = x_0^m - Y^m &=& ( x_0 - Y) ( x_0^{m-1} + x_{0}^{m-2}Y + \ldots + Y^{m-1}) \nonumber \\ &\leq& (x_0 - Y ) m x_0^{m-1} , \end{align}\] and because of this, Eq.(11 ) further yields the following. \[\begin{align} \label{ppa} x_{1 } & = & x_0 + \left\lfloor \frac{y -x_0^m}{mx_0^{m-1}} \right\rfloor \nonumber \\ & \geq & x_0 + \left\lfloor \frac{(Y-x_0 )m x_0^{m-1}}{mx_0^{m-1}} \right\rfloor \nonumber \\ &\geq& x_0 + (Y-x_0 ) -1 \nonumber \\ &\geq& Y -1 \nonumber \\ &=& y^{1/m} -1 \nonumber \\ &\geq& \lfloor y^{1/m} \rfloor -1 . \end{align}\tag{12}\] We have just proved that \(x_1 \geq Y -1\) and then further derived that \(x_{ 1 } \geq \lfloor y^{1/m} \rfloor -1\). \(None\)
\(None\) (e) Iteration \(i=1 \Rightarrow i+1=2\). Consider once more Eq.(5 ). \[\begin{align} \label{pp7} x_{2 } &=& x_1 + \left\lfloor \frac{Y^m - x_1^m}{mx_1^{m-1}} \right\rfloor \geq x_1 + \frac{Y^m - x_1^m}{mx_1^{m-1}} -1 \end{align}\tag{13}\] We distinguish two subcases then: (e1) and (e2), that can be generalized for any \(i>0\) by induction. \(None\)
\(None\) (e1) Iteration \(i=1 \Rightarrow i+1=2\) and \(x_{1} \geq Y\). \(None\)
\(None\) For \(i=1\) and \(i+1=2\) and assuming \(x_1 \geq Y= y^{1/m}\) we consquently obtain after noting that \(x_1^{m-1-j} Y^{j} \leq x_1^{m-1}\), \(0\leq j \leq m-1\), the following. \[\begin{align} \label{pp8} x_1^m - y = x_1^m - Y^m &=& ( x_1 - Y) ( x_1^{m-1} + x_{1}^{m-2}Y + \ldots + Y^{m-1}) \nonumber \\ &\leq& (x_1 - Y ) m x_1^{m-1} , \end{align}\tag{14}\] i.e. \(x_1^m - Y^m \leq (x_1 - Y) m x_1^{m-1}\). Reversing the inequality we obtain equivalently that \(Y^m - x_1^m \geq (Y- x_1 ) m x_1^{m-1}\). Therefore, for \(x_1 \geq Y\), Eq.(13 ) because of Eq.(14 ) gives the following. \[\begin{align} \label{pp9} x_{2 } & = & x_1 + \left\lfloor \frac{Y^m-x_1^m}{mx_1^{m-1}} \right\rfloor \nonumber \\ &\geq& x_1 + \left\lfloor \frac{(Y-x_1 )m x_1^{m-1}}{mx_1^{m-1}} \right\rfloor \nonumber \\ &\geq& x_1 + (Y-x_1 ) -1 \nonumber \\ &\geq& Y -1 \nonumber \\ & = & y^{1/m} -1 \nonumber \\ &\geq& \lfloor y^{1/m} \rfloor -1 . \end{align}\tag{15}\] We have just proved that if \(x_1 > Y = y^{1/m}\) then, \(x_2 \geq Y-1\) and also derived \(x_{ 2 } \geq \lfloor y^{1/m} \rfloor -1\). This generates the following lemma by induction.

Lemma 2. If \(x_i \geq Y= y^{1/m}\) then \(x_{i+1} \geq Y-1 = y^{1/m} -1\), for each \(i \geq 0\).

Note that \(x_i \geq Y= y^{1/m}\) is checked by comparing \(x_i^m \geq y\) instead and the same applies for the condition of Lemma 3. We have also proved the result summarized in Lemma 3 below.

Lemma 3. If \(x_i \geq Y= y^{1/m}\) then \(x_{i+1} \leq x_i\), for each \(i \geq 0\) Furthermore if it is not \(x_{i+1} < x_{i}\) then \(x_{i+1} = x_{i}\) and \(\lfloor y^{1/m} \rfloor = x_i\).

Proof. This is a consequence of Eq.(5 ) which shows that if \(x_i \geq Y= y^{1/m}\), then \(y- x_i^m < 0\), and \(x_{i+1} = x_i + \lfloor \leq 0 \rfloor \leq x_i\). The latter part of Lemma 3 is similarly derived from the discussion of part (d) earlier. If \(x_{i+1} = x_{i}\) then \(Y^m = y = x_i^m\) and \(y^{1/m} = \lfloor y^{1/m} \rfloor = x_i\). ◻

\(None\)
\(None\) We move to case (e2). By Eq.(12 ) \(x_1 \geq Y-1\). If it is not case (e1) where \(x_1 \geq Y\), then the only case left is \(Y > x_1 \geq Y-1\). This leads to case (e2). \(None\)
\(None\) (e2) Iteration \(i=1 \Rightarrow i+1=2\) and \(Y> x_{1} \geq Y-1\). \(None\)
\(None\) In this case \(x_1^m < Y^m\) and thus \[\begin{align} \label{pp10} y - x_1^m = Y^m - x_1^m &=& ( Y - x_1 )( x_1^{m-1} + x_{1}^{m-2}Y + \ldots + Y^{m-1}) \nonumber \\ &\geq& (Y- x_1 ) m x_1^{m-1} , \end{align}\tag{16}\] Subsequently, we have the following by way of Eq.(5 ) for \(i=1\). \[\begin{align} \label{pp10a} x_{2 } & = & x_1 + \left\lfloor \frac{y-x_1^m}{mx_1^{m-1}} \right\rfloor \nonumber \\ & = & x_1 + \left\lfloor \frac{Y^m-x_1^m}{mx_1^{m-1}} \right\rfloor \nonumber \\ &\geq& x_1 + \left\lfloor \frac{(Y-x_1 )m x_1^{m-1}}{mx_1^{m-1}} \right\rfloor \nonumber \\ &\geq& x_1 + (Y-x_1 ) -1 \nonumber \\ &\geq& Y -1 \nonumber \\ & = & y^{1/m} -1 \nonumber \\ &\geq& \lfloor y^{1/m} \rfloor -1 , \end{align}\tag{17}\] as in subcase (e1). The corresponding Lemmas are then as follows.

Lemma 4. If \(Y> x_i \geq Y-1= y^{1/m}-1\) then \(x_{i+1} \geq Y-1 = y^{1/m} -1\), for each \(i \geq 0\).

Lemma 5. If \(Y> x_i \geq Y-1= y^{1/m}-1\) then \(x_{i+1} \geq x_i\), for each \(i \geq 0\). Furthermore if it is not \(x_{i+1} > x_{i}\) then \(x_{i+1} = x_{i}\) and \(\lfloor y^{1/m} \rfloor = x_i\).

The proof of Lemma 4 follows from Eq.(17 ). The proof of Lemma 5 follows from Eq.(5 ) and a discussion similar to the proof of Lemma 3. \(None\)
\(None\) We wrap things up. Consider the sequence of values \(x_0 , x_1 , x_2 , \ldots\) obtained by applying the Newton-Raphson formula Eq.(5 ). One of three cases might apply. \(None\)
\(None\) Case 1. Let \(x_{n+1} = x_n\) occurs for the first time after a decreasing sequence i.e. we have \(x_0 > x_1 > \ldots > x_{n-1} > x_n = x_{n+1}\). Note that for a decreasing sequence \(x_{i+1} =x_i + \lfloor <0 \rfloor \leq x_i -1 < x_i\). In order to have \(x_{n+1} = x_n\) we must have that the quantity within the floor of Eq.(5 ) is non-negative, i.e. \(x_n\) is such that \(y- x_n^m \geq 0\), thus implying \(x_n^m \leq y\) or equivalently \(x_n \leq y^{1/m}\). This is sub-case (e2) earlier. If \(x_n =y^{1/m}\) then \(x_n = \lfloor y^{1/m} \rfloor\) and the calculation is over. Otherwise \(x_n <y^{1/m}\). This combined with the precondition of Lemma 2 (or Lemma 3) for \(i=n-1\) which leads to \(x_{n-1} > y^{1/m}\) results in the following: \[x_{n-1} > y^{1/m} \geq x_n.\] Note that if \(x_{n-1} = Y\) then \(x_n = x_{n-1}\) but we have \(x_{n-1} > x_{n}\). In addition, by Lemma 3 for \(i=n-1\) we know that \(x_n \geq Y-1 \geq \lfloor y^{1/m} \rfloor -1\). Combining the two we obtain the following. \[x_{n-1} > y^{1/m} \geq x_n \geq \lfloor y^{1/m} \rfloor -1.\] Therefore we can find \(\lfloor y^{1/m} \rfloor\) by just considering one of \(x_n\) and \(x_n +1\): one of these terms is \(\lfloor y^{1/m} \rfloor\). \(None\)
\(None\) Case 2. After a decreasing sequence we have a flip that is we have \(x_0 > x_1 > \ldots > x_{n-1} > x_n < x_{n+1}\). Note that by the base case and the choice of \(x_0\) we have \(x_0 \geq x_1\), therefore the sequence is non-increasing; in fact it is decreasing at the start unless \(x_0 = y^{1/m} =Y\), \(Y\) is integer, and then we can stop for \(x_0 =\lfloor y^{1/m} \rfloor\). Therefore in case 2 we have that \(x_{n-1} > x_n\) but \(x_{n+1} > x_n\) results in a flip. The sequence flips for the first time. By Lemma 2 for \(i=n-1\) we have that \(x_{n-1} \geq Y=y^{1/m}\) and \(x_{n} \geq Y-1\). By Lemma 3 for \(i=n-1\) we have that \(x_{n-1} \geq Y=y^{1/m}\) and \(x_{n} < x_{n-1}\). This is because the sequence is decreasing up to that point. For \(x_n\) we have obtained from above that \(x_n \geq Y-1\). There are two possibilities for \(x_n\): case (2a) where \(x_n \geq Y\) and case (2b) where \(x_n < Y\). If case (2a) is applicable, then Lemma 2 implies \(x_{n+1} \leq x_n\). However at \(n+1\) we have a flip with \(x_{n+1} > x_n\). Therefore case (2a) is impossible. We are left with case (2b) and \(x_n\) such that \(Y > x_n > Y-1\). Then Lemma 4 applies to give \(x_{n+1} \geq Y-1\), and Lemma 5 to derive \(x_{n+1} \geq x_n\). But since \(x_{n+1} > x_{n}\) equality \(x_{n+1}=x_n\) is not possible and \(x_{n+1} > x_n\) is confirmed If we combine the previous derivations we obtain \[x_{n-1} \geq Y= y^{1/m} > x_n \geq Y-1 = \lfloor y^{1/m} \rfloor -1.\] Then, \(\lfloor y^{1/m} \rfloor\) is one of \(x_n\) or \(x_n +1\). \(None\)
\(None\) Case 3. If \(x_{n+1}<x_n\), then continue with the next iteration. \(None\)
\(None\) Conclusion. \(None\)
\(None\) In either Case 1 or Case 2 we stop at an iteration where either the sequence flips sign (the next term become larger than the previous term) or the next term is equal to the previous one. If the next term is smaller than the one before ( Case 3) we continue to generate the next term of the sequence. As soon as we generate the flipping term (\(x_{n+1}\) in Case 2) or the repeating term (\(x_{n+1} = x_n\) in Case 1) we stop Newton-Raphson, and go back to \(x_n\). One of \(x_n\) or \(x_n +1\) is \(\lfloor y^{1/m} \rfloor\). We determine the answer by calculating \(x_n^{m}\) and \((x_n +1)^m\), as needed. In other words, in order to determine whether \(x_n = \lfloor y^{1/m} \rfloor\), we assume that if it is true \[\label{eqFloor} x_n \leq y^{1/m} < x_n +1 \Leftrightarrow x_n^m \leq \left( y^{1/m}\right)^m < \left( x_n +1 \right)^m \Leftrightarrow x_n^m \leq y < \left( x_n +1 \right)^m ,\tag{18}\] and thus we check the last part of Eq.(18 ). We do likewise to determine whether \(x_n +1\) is a candidate for \(x_n + 1 = \lfloor y^{1/m} \rfloor\). \(None\)
\(None\) We finally note that if the calculation of \(\lfloor y^{1/m} \rfloor\) relates to determining whether \(y\) is an integer power of an integer, we just need to verify whether \(x_n^m\) of \((x_n +1)^m\) is equal to \(y\) or not and thus the checking of Eq.(18 ) can be skipped. \(None\)
\(None\)

Figure 1: FindFloor(y,m) : Find \lfloor y^{1/m} \rfloor

 ◻

\(None\)
\(None\) Example 1. For the simple case \(y=10^8\) and \(m=8\), the sequence generated is \(16, 14, 12\), \(10, 10\) and \(x=10\) is reported.

\(None\)
\(None\) Example 2. For the case \(y=96889010407\) and \(m=13\), the sequence generated is \(8,7,7\) and \(x=7\) is reported.

\(None\)
\(None\) Example 3. For the case \(y=52523350144\) and \(m=7\), the sequence generated is \(32,34,34\) and \(x=34\) is reported.

\(None\)
\(None\) Example 4. For the case \(y=52523350141\) and \(m=7\), the sequence generated is \(32,34\) and \(x=33\) is reported.

3 A second approach↩︎

Because of the case complexity involved in the analysis of Algorithm 1 we pursued another interpretation of Integer Newton-Raphson for \(\lfloor y^{1/m} \rfloor\). We call this second approach Algorithm 2.

Lemma 6. Given a natural integer number \(y\) and a natural integer number \(m>1\) Algorithm 2 determines a natural integer number \(x\) such that \[x = \left\lfloor y^{\frac{1}{m}} \right\rfloor .\]

The proposed solution uses a different sequence of floor operations in converting the generic Newton-Raphson of Eq.(4 ) into Eq.(5 ) that was used in Algorithm 1.

Proof. \(None\)
\(None\) We are going to use a nested inequality of floor functions in addition to the ones established with the previous problem. We quote [6], for integer \(n,m\) (in our case positive integer) and real (in our case positive) \(x\). \[\label{nnp1} \lfloor \frac{\lfloor x \rfloor + m}{n} \rfloor = \lfloor \frac{x + m}{n} \rfloor\tag{19}\] \(None\)
\(None\) We proceed to using the Newton-Raphson approximation as follows.
\(None\)
\(None\) (a) Newton-Raphson iterative method. \(None\)
\(None\) The solution for \(f(x)=0\) of Eq.(3 ) as before is is \(x = y^{1/m}\). Moreover we derive that \(f^\prime (x) = - m x^{m-1}\). Let us then use the Newton-Raphson iterative method, where \(y^{1/m} = Y\) implies \(y = Y^m\) as follows. \[\begin{align} \label{npp3} x_{i+1} &=& x_{i} - \frac{f(x_i ) }{ f^\prime (x_i )} = x_i + \frac{y-x_i^m}{m \cdot x_i^{m-1}} = x_i - \frac{x_i}{m} + \frac{y}{m \cdot x_i^{m-1}} \nonumber \\ &=& \left( (m-1) x_i + \frac{y}{x_i^{m-1}} \right) \cdot \frac{1}{m}, \end{align}\tag{20}\] for \(i \geq 0\). The initial condition \(x_0\) will be determined and described later. \(None\)
\(None\) (b) Integer Newton-Raphson. \(None\)
\(None\) In order to obtain an integer approximation, we modify Eq.(20 ) so that we get integer values at various iterations. \[\begin{align} x_{i+1} &=& \label{npp4a} \left\lfloor \left( (m-1) x_i + \left\lfloor \frac{y}{x_i^{m-1}} \right\rfloor \right) \cdot \frac{1}{m} \right\rfloor , \end{align}\tag{21}\] which by way of Eq. (19 ) is equivalent to \[\begin{align} x_{i+1} &=& \label{npp4b} \left\lfloor \left( (m-1) x_i + \frac{y}{x_i^{m-1}} \right) \cdot \frac{1}{m} \right\rfloor . \end{align}\tag{22}\] The numerator and denominator of the internal fraction are integers. The numerator external fraction in Eq.(21 ) is an integer. The denominator is consider to be the \(m\) of \(1/m\), which is also an integer. Algorithm 2 uses Eq.(21 ), though its analysis would also use Eq.(22 ). \(None\)
\(None\) (c) Choice of the initial value \(x_0\). \(None\)
\(None\) This integer recurrence relation of Eq.(21 ) provides an integer sequence \(x_0 , x_1 , \ldots\) as long as \(x_0\), the initial condition, is also an integer. We first note the following.

We choose \(x_0\) such that \[\begin{align} \label{npp5} x_0 = 2^{\lceil \frac{\lfloor \lg{y} \rfloor+1}{m} \rceil } &\geq& 2^{ \frac{\lfloor \lg{y} \rfloor+1}{m} } \geq 2^{ \frac{\lg{y}}{m} } = y^{1/m} = Y \geq \lfloor y^{1/m} \rfloor. \end{align}\tag{23}\] i.e. \(x_0 \geq y^{1/m} = Y \geq \lfloor y^{1/m} \rfloor\). Starting with \(y\), finding \(\lceil \lg{y} \rceil\) and \(\lfloor \lg{y} \rfloor\) is easy as it requires shift operations and can be done in \(O(\lg{y})\) shifts. Therefore \(x_0\) is easy to compute and is calculated the way described. \(None\)
\(None\) (c) Minimization of Newton-Raphson term of Eq.(22 ). \(None\)
\(None\) From Eq.(22 ) that is equivalent to Eq.(21 ) we proceed as follows by isolating the argument of the floor function. \[\begin{align} f(x) &=& \label{npp4c} \left( (m-1) x + \frac{y}{x^{m-1}} \right) \cdot \frac{1}{m} \end{align}\tag{24}\] thus transforming equation Eq.(22 ) into the following form. \[\begin{align} x_{i+1} &=& \label{npp4d} \left\lfloor f(x_i ) \right\rfloor . \end{align}\tag{25}\] We observe the following \[f^\prime (x) = \left( 1 - \frac{1}{m} \right) - y \cdot \left( 1 - \frac{1}{m} \right) x^{-m} .\] For \[f^\prime (x) = 0 ,\] we obtain (assuming \(m \neq 1\), which is the case) \[x= Y= y^{\frac{1}{m}} .\] Furthermore, \[f^{''} (x) = y m \left( 1 - \frac{1}{m} \right) x^{-m+1},\] and setting \(x= y^{\frac{1}{m}}\) we obtain \[f^{''} (y^{\frac{1}{m}}) = y m \left( 1 - \frac{1}{m} \right) \cdot \frac{1}{y} \cdot \frac{1}{y^{\frac{1}{m}}}\] which is positive for \(1-1/m>0\), which is the case since \(m>1\). Therefore function \(f(x)\) has a minimum at \(x= y^{\frac{1}{m}}\) and calculating that minimum \[f(x)\left|_{x= y^{\frac{1}{m}}} \right. = y^{\frac{1}{m}} .\] Therefore from Eq.(24 ) and Eq.(25 we obtain the following. \[\begin{align} x_{i+1} &=& \left\lfloor \left( (m-1) x_i + \left\lfloor \frac{y}{x_i^{m-1}} \right\rfloor \right) \cdot \frac{1}{m} \right\rfloor \nonumber \\ &=& \label{npp5a} \left\lfloor f(x_i ) \right\rfloor \geq \lfloor y^{\frac{1}{m}} \rfloor. \end{align}\tag{26}\]

We obtain the first of three lemmas to follow.

Lemma 7. If \(x_0 \geq y^{\frac{1}{m}} \geq \lfloor y^{\frac{1}{m}} \rfloor\), then \(x_i \geq \lfloor y^{\frac{1}{m}} \rfloor\).

We note that by Eq.(23 ) it is indeed \(x_0 \geq y^{\frac{1}{m}}\), and also \(x_0 \geq \lfloor y^{\frac{1}{m}} \rfloor\).

\(None\)
\(None\) (d) Sequence \(x_0 , x_1 , x_2 , \ldots\). \(None\)
\(None\) From Eq.(21 ) or equivalently Eq.(22 ) we obtain the following. \[\begin{align} \tag{27} x_{i+1} &=& \left\lfloor \left( (m-1) x_i + \left\lfloor \frac{y}{x_i^{m-1}} \right\rfloor \right) \cdot \frac{1}{m} \right\rfloor \\ &=& \tag{28} \left\lfloor \left( (m-1) x_i + \frac{y}{x_i^{m-1}} \right) \cdot \frac{1}{m} \right\rfloor . \end{align}\] Consider the case \(i=0\) and thus \(i+1 =1\). \[\begin{align} x_{1} &=& \label{npp6b} \left\lfloor \left( (m-1) x_0 + \frac{y}{x_0^{m-1}} \right) \cdot \frac{1}{m} \right\rfloor \end{align}\tag{29}\] From Eq.(23 ) we have \(x_0 \geq y^{1/m}\) and therefore \(y/ x_0^{m-1} \leq x_0\). Eq.(29 ) then yields the following. \[\begin{align} x_{1} = \label{npp6c} \left\lfloor \left( (m-1) x_0 + \frac{y}{x_0^{m-1}} \right) \cdot \frac{1}{m} \right\rfloor &\leq & \left\lfloor \left( \left( m-1 \right) x_0 + x_0 \right) \cdot \frac{1}{m} \right\rfloor = \lfloor x_0 \rfloor \leq x_0. \end{align}\tag{30}\] We could use the same argument to show that \(x_2 \leq x_1\). However we need \(x_1 \geq y^{1/m}\) but by Lemma 7 we only have \(x_1 \geq \lfloor y^{\frac{1}{m}} \rfloor\). The only case that \(x_1 \geq y^{1/m}\) is NOT the case is for \(\lfloor y^{\frac{1}{m}} \rfloor = y^{1/m}\) but then we stop the Newton-Raphson calculation . We thus get the following second lemma.

Lemma 8. If \(x_0 \geq y^{\frac{1}{m}} \geq \lfloor y^{\frac{1}{m}} \rfloor\), then \(x_i \geq y^{\frac{1}{m}}\). Moreover if \(x_i > y^{\frac{1}{m}}\), then \(x_{i+1} < x_i\).

Proof. The first part is Lemma 7. For the second part, if \(x_i > y^{\frac{1}{m}}\) we utilize Eq.(27 ) and similarly to the derivation \(x_1 \leq x_0\) earlier, we derive first \(x_i^m > y\) and then \(x_i > a= y / x_i^{m-1}\). \[\begin{align} \tag{31} x_{i+1} &=& \left\lfloor \left( (m-1) x_i + \left\lfloor \frac{y}{x_i^{m-1}} \right\rfloor \right) \cdot \frac{1}{m} \right\rfloor \nonumber \\ &=& \left\lfloor \left( (m-1) x_i + \left\lfloor a \right\rfloor \right) \cdot \frac{1}{m} \right\rfloor \nonumber \\ &\leq& \left\lfloor \left( (m-1) x_i + x_i -1 \right) \cdot \frac{1}{m} \right\rfloor \nonumber \\ &=& \tag{32} \left\lfloor \left( m x_i - 1 \right) \cdot \frac{1}{m} \right\rfloor \nonumber \\ &\leq& x_{i}-1 < x_i \end{align}\]  ◻

The following lemma covers the case \(x_i = y^{\frac{1}{m}}\).

Lemma 9. If \(x_0 \geq y^{\frac{1}{m}} \geq \lfloor y^{\frac{1}{m}} \rfloor\), then \(x_i \geq y^{\frac{1}{m}}\). If \(x_i \leq y^{\frac{1}{m}}\), because \(x_i \geq \lfloor y^{\frac{1}{m}} \rfloor\) and \(x_i\) is integer, we have \(x_i = \lfloor y^{\frac{1}{m}} \rfloor = y^{\frac{1}{m}}\).

Proof. The first part is Lemma 7. If \(x_i \geq y^{\frac{1}{m}}\) and it cannot be \(x_i > y^{\frac{1}{m}}\) the only possibility left is \(x_i = y^{\frac{1}{m}}\) rather than the stated \(x_i \leq y^{\frac{1}{m}}\). Since \(x_i\) is an integer it follows that \(x_i = y^{\frac{1}{m}} =\lfloor y^{\frac{1}{m}} \rfloor\). ◻

\(None\)
\(None\) Consider the sequence of values \(x_0 , x_1 , x_2 , \ldots\) obtained by applying the Newton-Raphson formula Eq.(27 ). We distinguish three cases. \(None\)
\(None\) Case 1. If \(x_{i+1} < x_i\) we continue. \(None\)
\(None\) Case 2. If \(x_{i+1} \geq x_i\), we stop. \(None\)
\(None\) By Lemma 7 we have \(x_i \geq \lfloor y^{\frac{1}{m}} \rfloor\). By the stopping condition we have \(x_{i+1} \geq x_i\) and by combining the two we obtain the following. \[x_{i+1} \geq x_i \geq \lfloor y^{\frac{1}{m}} \rfloor.\] There are two possibilities: (a) \(x_i \leq y^{\frac{1}{m}}\) or (b) \(x_i >y^{\frac{1}{m}}\). Case (b) is impossible because it contradicts Lemma 8 that states it should be then \(x_{i+1}<x_{i}\). Case (a) is the only case possible. We obtain \[y^{\frac{1}{m}} \geq x_i \geq \lfloor y^{\frac{1}{m}} \rfloor,\] utilizing Lemma 7 . This implies \(x_i = y^{\frac{1}{m}} = \lfloor y^{\frac{1}{m}} \rfloor\). \(None\)
\(None\) Case 3. We stop when \(x_i = y^{1/m}\) or when \(y^{1/m} > x_i\). We test equivalently \(x_i^m = y\) or \(y > x_i^m\). \(None\)
\(None\) By Eq.(26 ), we have \(x_{i+1} = \lfloor f(x_i ) \rfloor\). We then claim that \(f(x_i ) \geq x_i\). Suppose this is not the case and we have instead \(f(x_i ) < x_i\). By Eq.(26 ), \(x_{i+1} = \lfloor f(x_i ) \rfloor \leq f(x_i ) < x_i\). Then we have case 1 and for case 1 we continue iterating than stopping. Therefore we must have \(f(x_i ) \geq x_i\). Then we obtain the following. \[\begin{align} f(x_i ) & \geq & x_i \Leftrightarrow \nonumber \\ \left( (m-1) x_i + \frac{y}{x_i^{m-1}} \right) \cdot \frac{1}{m} &\geq& x_i \Leftrightarrow \nonumber \\ x_i^m &\leq& y^{\frac{1}{m}} \Leftrightarrow \nonumber \\ \label{npp7} x_i &\leq& y^{\frac{1}{m}}. \end{align}\tag{33}\] From Eq.(33 ) and combining with Lemma 7 we have the following. \[\lfloor y^{\frac{1}{m}} \rfloor+ 1 > y^{\frac{1}{m}} \geq x_i \geq \lfloor y^{\frac{1}{m}} \rfloor ,\] where the third inequality is by way of Lemma 7, and the second by the derivation above. This implies \(x_i = \lfloor y^{\frac{1}{m}} \rfloor\). \[\lfloor y^{\frac{1}{m}} \rfloor+ 1 > y^{\frac{1}{m}} \geq x_i \geq \lfloor y^{\frac{1}{m}} \rfloor ,\] that leads to \(x_i = \lfloor y^{\frac{1}{m}} \rfloor\). ◻

\(None\)
\(None\)

Figure 2: FindFloor2(y,m) : Find \lfloor y^{1/m} \rfloor
Figure 3: CheckCandidateSolution(x,y,m) : Is x= \lfloor y^{1/m} \rfloor?

\(None\)
\(None\) Example 5. For the simple case \(y=10^8\) and \(m=8\), the sequence generated is \(16,14,12,10,10\) and \(x=10\) is reported.

\(None\)
\(None\) Example 6. For the case \(y=96889010407\) and \(m=13\), the sequence generated is \(8,7,7\) and \(x=7\) is reported.

\(None\)
\(None\) Example 7. For the case \(y=52523350144\) and \(m=7\), the sequence generated is \(64, 54, 46, 40, 36\), \(34, 34\) and \(x=34\) is reported.

\(None\)
\(None\) Example 8. For the case \(y=52523350141\) and \(m=7\), the sequence generated is \(64, 54, 46, 40\), \(36, 34, 33, 34\) and \(x=33\) is reported.

4 Conclusion↩︎

If one compares the performance of the two algorithms through the series of examples indicated, they show that Algorithm 1 is slightly better than Algorithm 2 for the last two examples. The choice of initial value \(x_0\) that is more targeted in Algorithm 1 seems to make the difference.

References↩︎

[1]
G. L. Miller. Riemann’s hypthesis and tests for primality. Journal of computer and system sciences, 13, 300-317 (1976), Academic Press.
[2]
M. O. Rabin. Probabilistic algorithm for testing primality. Journal of Number Theory, 12, 128-138 (1980), Academic Press.
[3]
M. Agrawal, N. Kayal and Nitin. Saxena. PRIMES is in P. Annals of Mathematics, 160(2), 781-793.
[4]
E. Bach and J. Shallit. Algorithmic number theory, Volume 1: Efficient algorithms. The MIT Press, 1997.
[5]
W. Rudin. Principles of Mathematical Analysis. 3rd edition, McGraw-Hill, 1976.
[6]
Wikipedia. https://en.wikipedia.org/wiki/Floor_and_ceiling_functions[Accessed: 2026/05/28].

  1. CS Department, New Jersey Institute of Technology, Newark, NJ 07102, USA. Email: alexg@njit.edu↩︎