Internat. J. Math. & Math. Sci. Vol 9 o. 2 (1986) 261-266 261 SEQUENCES IN POWER RESIDUE CLASSES DUNCAN A. BUELL Department of Computer Science Louisiana State University Baton Rouge, LA 70803 and RICHARD H. HUDSON Department of Mathematics University of South Carolina Columbia, SC 29208 (Received June 13, 1985) Using A. Well’s estimates the authors have given bounds for the largest prime ABSTRACT. such that all primes P0 For have sequences of quadratic residues of length PO the smallest prime having 8 m P m m. 3(mod 4) consecutive quadratic residues is The reason for this phenomenon is investigated in this paper and th power the theory developed is used to successfully uncover analogous phenomena for r and P0 (mod 4). E residues, 2, r r even. KEY WORDS AND PHRASES. Sequences of consecutive r zeros and ones, linear least squares fit. power residues, random sequences of I. INTRODUCTION. In [I] the authors used Well’s estimates [2] to give explicit bounds for the largest prime P0 such that all primes assigned length m primes having is m. P0 P have sequences of quadratic residues of pre- Unexpectedly, the authors discovered that for all m < 8 the smallest consecutive quadratic residues are congruent to 3(mod r) and that P 0 l(mod 4). In this paper we develop a theory which suggests that primes E 3(mod 4) can be expected to have a longest sequence of quadratic residues (or non residues) which is, in the mean, approximately one longer that the longest sequence for primes conparable size. Data in Table l(mod 4) of support this theory. Using our theory we predicted that primes 5(mod 8) can be expected to have a longest sequence of quadratic residues which is, in the mean, about I/2 longer than the longest sequence for primes in Table 2. of comparable size. This is supported by data In Table 5 we observe that (as aconsequence) the smallest primes having a sequence of 1,2,3 E l(mod 8) 5(mod 8) rather than E l(mod 4) I0 consecutive quadratic residues, respectively, are all l(mod 8). DUNCAN A. BUELL and RICHARD H. HUDSON 262 The data in Tables 3 and 4 support our theory regarding the approximate magnitude th 2 power residue sequences, r of the mean excesses in the lengths of the longest r and even, for primes E r+l (mod 2r) versus the corresponding mean lengths for prime E 6,8. l(mod 2r); data is supplied for r Additional supporting’material can be obtained from the first author in [3] where th r powers (mod p) is data for all cosets formed with respect to the subgroup of presented and the mean value of the longest sequence in any coset is observed to be closely approximated by logrp for all integers r _> 2, 70,000 < p < 300,000; see Table 6. 2. NOTATION. For each fixed power residues modulo the prime let m(g) be the smallest prime th We which, as customary, we take to be E l(mod r). p and m(g) the largest prime such such that n(p) p n(p) that 3. denote the length of the longest sequence of r n(p) let r RANDOM SEQUENCES OF ZEROS AND ONES. Consider all n-character strings of E shall call a substring of t zeros and n-t For convenience we ones. or more consecutive zeros an E-substring. If event which is a function of a variable x and which happens with probability X shall say that Let happens almost surely if R(n,,t) P(X) tends to as denote the number of n-character strings with x t X is an P(X) we tends to infinity. zeros and n-t ones which do not contain and -substring. THEOREM 3.1 R(n+l,E,t) (b) R(n,E,t) > O, we have t > For n (a) R(n,,t) + R(n,,t-l) R(n-,,t-l), i>O The recursion for part (a) is easy. PROOF. If we append a "l" to and n-character string with no -substring then we get an (n+l)-character string with no -substring, accounting for the addend R(n,,t). If we append a "0" to an n-character string with no -substring then we get an (n+i)-character string which has no -substring unless the original string ended with -1 zeros, accounting for the second and thrird addends on the right-hand-side of formula (a). To prove (b) we use the two variable generating function F(x,y) R(n,,t) (x n-t) (yt). Using the recursion in (a) and taking into account the "initial conditions" we get F xF + yF xyF + y Thus F(x,y) where (l-yE)/(1-y). G(y) (; l-y l-x-y+xy E G l-xG The remainder of the proof is easily supplied by the reader using simple algebra to extract coefficients. Let s(n,E,t) 0 other digits, denote the number of n-character strings with through r-l, with no E-substring. following theorem as its proof is entirely similar to the above. THEOREM 3.2 (a) For n s (n+l r t E > 0 we have r r t zeros and n-t We may omit the proof of the SEQUENCES IN POWER RESIDUE CLASSES Sr(n,,t) (b) v(n) Let THEOREM 3.3 w(n) n(). (b) If rt then (c) Let n v(n) logr(n)+w(n) zeros. t )( )(I Then + n(t-) v(n) rt then n Then almost surely does not happen. be the event that there exists no -substrlng. 2 P(E 2) If w(n) denote any tends to infinity. n be the event that there exists at least one -string. P(X I) < X tends to infinity as Consider an arbitrary n-character string having X Let (d) (-l)i(r-l) n-t+l-i’n-t+l( i )(.n-in_t) denote the length of the longest -substring and function such that (a) i=O 263 logrn-W(n) almost surely happens. PROOF. (a) The probability that at least one -substrings. n(t-) P(X I) (n-+l)- Thus (n-+l)(a), n t where t (t-l)... (t-+l) n(n-l)... (n-+l) a Henceforth, we assume the easy inequality t-I t for n n-i t > i n a from which it follows that (b) Let n If log n() P(X I) r -w(n) (c) n(r- + w(n), r(n) X - P(X I) < n(t/n) so that (a). Then ). r then tends to zero. Let (t/n) < and apply part rt P(X I) < 0, r -w(n) /n. As be the number of -substrings. n tends to infinity, Using an appropriate version of Chebyshev’s inequality we have P(X2) As before, E(X2) E2(X) < E(X) E(X I. (n-+l)(a). 2)() 2( n-2+2 2 -I + 2 Then (n-2 i=l 2( It is not difficult to see that n-2 (t-2) n-2+i, +l+i)(t_2+i) n-2+2 2 + n- (n-+l)(t_). -I )a2 + (n-2+l+i)a2_i + (n-+l)(a) 2 i=l P(X2) -I. (n-)a2 DUNCAN A. BUELL and RICHARD H. HUDSON 264 Using the aforementioned inequality we have (n-2+2) (n-2+I) (a2) 2 < I, (n-+l)a a2_i a a2 < n- i a2 so that 2-< (_-) Cosequently, n-2+2 2 2 " )a2+2 i=] P(X 2) < (n-2+I+i) a2-i -I (n-+l) 2 a 2 so that 2 i=l P(X2 (n-2+I+i) a2_i (n-+l) 2 a [ a2-i 2 ..,2 (.-i < 2 i=l a (i=l (n-) or < P(X2) n2 (-+I) n- i=l (t--) 2 i n- (n-+l)(t-) t- i Summing the geometric series completes the proof of (c). (d) Let n P(X2) Let =log r For large n < 2r (r-I n-r (r-l) (r) (I + (n(r-i) n-w(n). (I + so that by part (c) rt n-r Then there is a constant ) < exp( 2 (r_ m such that < m log n so that 2 < exp .m log2n [n-2m n-r log n this is easily bounded by 2 so that P(X 2) 4r (n(r_l)) (r) 4r -w(n) (n(r_l)) riO grn)r 4r (_l)r -w(n) 0 as n completing the proof of Theorem 3.3. 4. CONSEQUENCES OF 3. We can visualize coset membership formed with respect to the subgroup of r th powers (mod p) as a string of digits, each digit from the range 0 to r-l, with 0 correth sponding to the r powers. These strings are clearly not randomly determined. Nonetheless the theory in 3 suggests that to the extent that n(p) can be thought of as a random variable we should expect its mean value to be on the order of logrp. Specifically, in Table 6 we give coefficients a and b produced by a linear least squares fit of n(p) to n(p) Tables 2 m In p+b. to 6 illustrate the central feature of this note. then we have (p-l)/2r r th If powers (and similarly for the other r is even and r-1 cosets formed with respect to the subgroup of r th powers (mod p)) in the interval to (p-l)/2 if p l(mod 2r) and in the interval to p-1 if p r+l(mod 2r). Data in the following tables suggest that mean lengths of n(p) for primes r+1(mod 2r) exceed those for primes E 1(mod 2r) by in 2/in r for r even and 2. The mean difference of I, e.g., for r=2 translates into an expected value for n(p) for p 3(mod 4) equal to the expected value for N(q) for a prime l(mod 4) approximately twice the size of p. 265 SEQUENCES IN POWER RESIDUE CLASSES n(p) The theory which allows us to conjecture approximate mean differences in between the residue classes produces estimates which are startlingly close to actual data given the obvious differences between r th power residue distributions and random However, our theory represents only a partial first hypothesis, and character strings. a superior explanation for the phenomenon described here may well be developed. None- theless statistical tests (see [4] for the standard Z-test) provides better than 99% confidence that l(mod 2r) primes r+l(mod 2r), r=2,4,6,8, constitute and primes two entirely different sample populations. Of course this note raises a number of questions, many very difficult. 2 r m() % it is not at all obvious for large 3(mod 4) and m(E) E 1(mod 4) % Even for whether the probability that increases or decreases or even has a limit as goes to infinity. 5. COMPUTATION. Originally computations were done in VS FORTRAN (IBM’s FORTRAN 77) on the IBM 3033N of the System Network Computer Center at Louisianna State University. The computation was redone, also in FORTRAN, on the VAX 11/780 running VMS of the Department of Computer Science at L.S.U. Most of the statistical results were obtained using SAS on the IBM 3033. Table i Primes l(mod 4) r 2 Primes E 3(mod 4) Range # p Mean Dev. #p Mean Dev. <70000 140000 210000 280000 350000 420000 3449 12.738 14.938 15.731 16.234 16.566 16.886 2.4q6 3029 2914 2790 2762 2709 3485 3046 2883 2835 2783 2704 13.809 16.007 16.742 17.245 17.572 17.897 2.445 1.905 1.907 1.923 1.946 1.941 1.995 1.969 1.992 2.046 1.982 Table 2 Primes =- l(mod 8) r 5(mod 8) Rang. # p Mean Dev. #p Mean Dev. <70000 140000 210000 280000 1820 1606 1549 1482 6.359 7.545 7.954 8.172 1.438 1.173 1.170 1.083 1860 1620 1535 1508 6.985 8.078 8.506 8.672 1.302 0.959 Primes l(mod 12) r n r/En 2 i 1.071 1.069 1.011 1.011 1.006 1.011 4 Primes Table 3 Difference in Mean 1.024 0.967 Difference in Mean r/En 2 0.5 .626 .533 .552 .500 6 Primes 7(mod 12) Range #p Mean Dev. #p Mean Dev. <70000 140000 210000 280000 1830 1601 1537 1499 4.892 5.737 6.064 6.253 1.073 0.857 0.864 0.822 1851 1624 1548 1480 5.307 6.206 6.438 6.680 1.019 0.794 0.763 0.766 Difference in Mean En r/En 2 .415 .469 .374 .427 386.. DUNCAN A. BUELL and RICHARD H. HUDSON 266 Table 4: Primes -= l(mod 16) Range #p Mean Dev. 70000 140000 210000 280000 909 803 776 739 4.183 4.923 5.173 5.361 1.011 0.857 0.776 0.872 i 2 3 4 5 6 7 8 9 m() 5 37 29 41 1153 2689 32233 103529 i01 269 389 661 1301 4621 4261 i0 #p Mean Dev. 911 803 773 743 4.535 5.296 5.542 5.681 0.821 0.693 0.683 0.730 r %n r/En2--.333.. .352 .373 .369 320 4 m()(mod 8) m()(mod 8) 1 1 1 1 1 5 5 5 5 5 5 5 5 5 5 m Regression n(p), 70000 < p < 300000 Table 6: Difference in Mean 9(mod 16). Primes Table 5: m() 8 r r m b 2 3 4 5 1.436 0.910 0.726 0.612 -1.088 -0.970 -0.608 -0.622 np +__b i/En r 1.443 0.910 0.721 0.621 We wish to express sincere thanks to Andrew Thomason, who has declined to accept co-authorship of this paper, for insight, help and particulary for ACKNOWLEDGMENTS. suggestions regarding the theorems in 3. REFERENCES i. BUELL, D. A., and HUDSON, R. H., "On Runs of Consecutive Quadratic Residues and and Quadratic Nonresidues", BIT 24 (1984), 243-247. 2. WELL, A., 3. BUELL, D. A., and HUDSON, R. H., "Sequences in Power Residue Classes", L.S.U. Computer Science Technical Report, Baton Rouge, LA. 4. WALPOLE, R. E., Introduction to Statistics, MacMillian, New York, 1968. Algbriques et les Varietes qui s’en Deduisent", "Su les Courbes Actualites Math. Sci. No. 1041 (Paris, 1945), deuxime partie, Section IV.