Decimal expansion of 1/p, where p is prime - length of repeating sequence?

Are we talking past each other here? We need to clarify something immediately: 7^3 is not a prime, and so therefore it is necessarily not a full reptend prime. I have left the realm of full reptend primes behind since @csstudent broadened our discussion. We have left the realm of primes in general behind, in light of your observation and what I am herein calling the Primitive Root Theorem.

Also, both 7^3 and 337 are prime powers (337 = 337^1), and so they both fit my criteria for candidates for the number x that @csstudent desired. Which one “is a good number”; i.e., which one is such that its reciprocal has the longer decimal periodic representation? Well, before you told me, I had no idea, and I made no claim that I had an idea (without just doing the division).

Also, you’re asking for the next “good number”. You have not defined what a “good number” is, but from context I am inferring that it is an integer whose reciprocal has longer periodic decimal representation than any which has come before it (this is a very big assumption on my part; if I am mistaken, I apologize and ask only for clarification). As I know you know, there is no upper bound for the period of the decimal representation of a rational number, so I am always approaching this with @csstudent’s upper bound of some natural number n, so the set of numbers we must consider is finite.

But here’s where your question has merit: as n becomes large, the problem of determining whether an arbitrary integer is a prime power and whether 10 is a primitive root modulo said integer becomes computationally intractible (without knowing the prime factorization of said integer). This is equivalent to the discrete logarithm problem. Eventually, we will get to the point that the necessary conditions I have given will become impractical to verify . . . and we will have no choice but to do a computer search, as you seem to imply. I assume this means just doing the long division, but perhaps you have something else in mind.

As to “Or is it obvious what it is?” The criteria I have outlined are necessary conditions. But they are pure. From a coding point of view, they will eventually become impractical. At that point, the next “good number” is not at all obvious to me.

https://ibb.co/F30C1PH

I plotted the period of the reciprocal of all numbers less than 1000 that are coprime to 10.

X axis represents the denominator and Y axis the period.

Orange points represent primes, red represent full primes and blue represent non-primes.

As we can see by those occasional pesky blue points on the top line it’s difficult to disregard them. As you both mention @DPRK, @RayMan, I think it will be a struggle to find theory that allows me to disregard many points at all, and that I may have to just do the division.

The theory is getting a bit complex for me so I need to study both of your responses a little before I continue I feel. Apologies if you feel I’m taking up too much of your time, do feel free to leave me to my devices if so.

One last observation that may be true looking at the graph, could we disregard primes if they are not full primes? The orange points are never very high and so perhaps this is useful? Sorry if either of you have already said this, I’m still trying to study your responses!

Thanks all (both)!!

Wow, there is so much to say here. We must agree to some definitions. I hope we can agree that a full reptend prime is a prime p such that \frac{1}{p} has a decimal representation with period of length p-1. Also, perhaps @DPRK had in mind that a good number is an integer m such that \frac{1}{m} has a decimal representation with period length greater than that of any integer smaller than it. One important note: I have inferred this definition from the context of @DPRK’s numerous illuminating posts; he may have something different in mind.

@Indistinguishable claimed some seven years ago, and I fully agree, that a prime p is a full reptend prime if and only if 10 is a primitive root modulo p. Neither of us have provided you with proof, but for now I hope you will take me at my word. The proof is related to the fact that \mathbb{Z}/p\mathbb{Z} is a finite field, and if 10 is a primitive root modulo p, then all the powers of 10 are invertible, and they cycle through all the nonzero congruence classes modulo p.

I have also claimed (very much without proof) that if m is a good number, then m=p^k for p prime, p \neq 2, p \neq 5, and 10 is a primitive root modulo m. These are necessary conditions, they are not sufficient conditions. As a mathematics student, you should be skeptical of my claim until it is proven, but I have discovered a truly remarkable proof of this theorem which this margin is too small to contain.

So, if you believe that, a prime which is not a full reptend prime is not a good number. In very plain language, yes we could “disregard primes if they are not full [reptend] primes.” We cannot disregard composite moduli, as @DPRK noted, and with whom I fully agree. But my claim is that those composite moduli must be of the form I have given.

As an aside, if we were to ignore composite moduli (which I just emphatically said we cannot), your graph gives a visual representation of what is known as the natural density of the set of primes for which 10 is a primitive root in the set of all primes. That natural density is known under the assumption of a generalized Riemann Hypothesis. It is known as Artin’s Conjecture on Primitive Roots. In other words (assuming the Riemann Hypothesis is true), as the upper bound on the x-axis approaches infinity, the proportion of red and orange dots asymptotically approaches the known density. Your graph is absolutely fascinating to me. Thank you for providing it.

I can no longer lay claim to the title of analytic number theorist, if in fact I ever could. But insofar as I am a mathematician at all, I am a pure mathematician, and number theory is the purest of the branches of mathematics. My approach to this has been completely pure. If you are merely looking for good computer code, there comes a point at which you might be better off not focusing on the beautiful theory I have expounded on at length, and focusing instead on more practical considerations. Primitive roots and field theory more generally are topics which captivate me, but you could write code to solve this problem without even knowing what they are. Such is the Straight Dope.

Thanks for sharing your problem.

Apologies. Indeed let’s define a set A of “good numbers” as numbers m>3 such that the period of 1/m is strictly longer than the period of any n with n<m. [If the expansion terminates, take the period to be 0 or 1, doesn’t really matter.] That way

A = \{ 7,\,17,\, 19,\, 23,\, 29,\, 47,\,\ldots\}

and a set B of “full reptend primes” (?), i.e. prime numbers for which 10 is a primitive root. Now

B = \{ 7,\, 17,\, 19,\, 23,\, 29,\, 47,\, \ldots \}

with B \subseteq A.

Now you can start to ask questions, like what numbers are in A but not in B. Following your lead and running a quick computer program verifies that the only exceptions less than 10^7 are 17^2 and 19^2, but it does not really matter how long you run your program; to prove something in general you need a “pure” proof. (which, speaking generally and not necessarily about this topic, may be “elementary” or more generally may utilise analytic, algebraic, geometric, etc. “tools” which I hope are taught to prospective computer scientists and not just mathematics students)

We are in absolute agreement here. I agree absolutely with your definitions, proposals, and I especially agree that my claims, from a mathematical point of view, are worthless without proof. I have provided no proof for my claims. Period.

But since we are on a messageboard and not at a number theory conference, I hope I can wave my hands enough for me to say things like “but for p prime and k \in \mathbb{N}, \mathbb{Z}/p^k\mathbb{Z} is a finite field, and so our proof proceeds akin to the one for \mathbb{Z}/p\mathbb{Z}.” And at this point I should really stop, because you are right, it doesn’t matter without a proof. My proof writing days are behind me now, but it might be fun to prove this. I’m sure it is not worthy of publication, this is all well-established number theory and ring theory, etc…

Thank you for your feedback and clarification, @DPRK, this conversation is truly fascinating. I should stop, I might delude myself into thinking I am a mathematician.

Yes, I am becoming more confident in my claim as I spent a pleasant evening remembering all this stuff about ring theory. If m=p^k is a prime power, then \mathbb{Z}/p^k\mathbb{Z} is a finite field of order p^k, and \mathbb{Z}/p^k\mathbb{Z}^\times is a cyclic group of order \phi(p^k)=p^{k-1}(p-1), which is certainly not isomorphic to the group of units modulo p. However, since p-1 divides the order of this cyclic group, \mathbb{Z}/p^k\mathbb{Z}^\times contains a cyclic Sylow p-subgroup isomorphic to \mathbb{Z}/p\mathbb{Z}^\times via the surjective homomorphism that reduces an equivalence class representative of \mathbb{Z}/p^k\mathbb{Z}^\times modulo the elements of the base field, unique up to isomorphism (whose structure is given by the Fundamental Theorem of Finite Abelian Groups) via a + (p^k) \mapsto a + (p). This is the quotient group we know and love. If 10 is a primitive root modulo m=p^k, then 10 is a generator of this cyclic group, and we are in the exact same setting that we were in in the case of m=p prime. Given m=p^k, p prime, the decimal period of \frac{1}{m} is maximal if and only if 10 is a primitive root modulo m.

I have leaned heavily on the text of Dummit and Foote, Abstract Algebra, for this latest observation. Speaking informally here, the decimal period of \frac{1}{m} where m=p^k is maximal if and only if 10 is a primitive root modulo m for the reason I mentioned earlier: the powers of 10 are all invertible, and run through all the positive integers relatively prime to m, of which there are \phi(m)=p^{k-1}(p-1) of them. Again, speaking informally, if 10 is not a primitive root modulo m=p^k, as you do long division for 1/m, you have fewer remainders than you do if 10 is a primitive root modulo m. In such a case, the remainders repeat earlier than they would if the remainders ran through all the possibilities, and the period of the decimal representation is shorter than the maximal possible \mbox{ord}_m(10). The interested reader can fill in the details.

@DPRK, in your last post prior to this one, you are replying to me, as the little symbol with the arrow pointing to “RayMan” suggests. The name @csstudent does not appear anywhere in your post. I am interested in the following:

I do not know for whom this quote is intended. I will assume it is for the interested reader, and not me personally, because I believe that you would not act so uncollegially as to lecture me on mathematical rigor, based on my many contributions to this conversation.

it’s not (unless k=1)

Could you please explain what you mean, here? If m is fixed, then the period length is whatever it is, say a(m), and 10 either is a primitive root or is not, but maximality means that a(n) \le a(m) for n \le m. When 10 is not a primitive root, how can we find n with a(n)>a(m)? Cf also the marginal case when m=3 and 10 is not a primitive root, and a(3)=1, but one can’t beat that by going lower.

Hmm, that was supposed to be a comment to a quote from, and addressed to, @csstudent who has been running various versions of the program in question and seemed anxious that non-elementary theory may pop in, but I should say flat out that I have not nor plan to lecture anyone on anything, least of all mathematical rigor, and if it seemed I was then I apologize unreservedly to @csstudent and of course to you, who have spent an order of magnitude more time than I actually thinking about the problem and writing long, detailed answers.

Oh my, you are absolutely correct. I have claimed now a couple of times in this thread that \mathbb{Z}/p^k\mathbb{Z} is a finite field. You are right, it is not. This is the kind of oversight a colleague calmy points out in the manner that you did before one embarrasses oneself, such as by posting it multiple times on a public messageboard.

What I meant to say (a phrase often used by mathematicians who are shown to be wrong), is that for p prime, k \in \mathbb{N}, there exists a finite field of order p^k, call it \mathbb{F}_{p^k}. It is not isomorphic to \mathbb{Z}/p^k\mathbb{Z}, rather it is isomorphic to \mathbb{F}_p[x]/(p(x)), the ring of polynomials in one variable with coefficients in \mathbb{F}_p modded out by an irreducibe polynomial p(x) \in \mathbb{F}_p[x] of degree k. Thank you for the correction. If I may feebly attempt to salvage my earlier line of reasoning, \mathbb{F}_{p^k} contains \mathbb{Z}/p^k\mathbb{Z} as a subring, and if 10 is a primitive root modulo p^k, then 10 is a generator of \mathbb{Z}/p^k\mathbb{Z}^\times, and we are back where I was earlier.

I will address your other points later, but I am off to work right now. I just wanted to address my glaring error that you so gently and correctly pointed out. Thank you.

I don’t think that is quite what you mean, for example the first has characteristic p and the second has characteristic p^k, also they happen to have the same number of elements, but I think I see what you are getting at, just not sure yet it directly helps resolve @csstudent 's problem

I must say thanks to both of you @DPRK and @RayMan.

I’ve just been able to read all the posts in more detail and process them properly. Unfortunately, as you both point out it does seem as though I won’t be able to use any actual theory to rule out numbers in my algorithm / cut out my list of potential answers just purely due to the fact I don’t have anything that is proven concretely via rigorous proof.

I spent a lot of time researching into this topic and at least I can say I learned a lot more number theory than I would have as part of the research, even if I cannot use it.

One thing I wanted to mention was regarding the comment you made (@RayMan) about the graph, it really fascinated me also. The different ‘lines’ that the regular primes seemed to follow was really interesting and not something I think I could grasp as of this moment with my elementary knowledge of number theory.

Once again, I do wholeheartedly thank the both of you for your valuable time and effort spent in entertaining my task and adding really insightful comments to the discussion.

I was thinking that as part of your project you will need to do the research and be able to use some theory to speed up your algorithm. Why do you write

?
Like I suggested, maybe you can indeed rule out (most) non-primes. Maybe ultimately not, but like @RayMan we need to spend more than a couple of seconds thinking about it. Also, if it turns out that not, it may still be worth mentioning in your assignment why not (turns out to depend on Artin’s such-and-such unresolved conjecture, or whatever)

The research I’ve done goes far beyond the scope of the task. In reality, the module is delivered by the maths side of the course, and such algorithmic refinement isn’t really expected of the students. To add to that, the largest n that will be used to test the algorithm is 500, i.e. find maximal x<500 such that 1/x has the largest period.

My algorithm that actually just manually checks the period of the reciprocals works quicker than any other test at the moment but I just thought having some theory in there to eliminate possibilities would be neat and may score me some extra points.

It is more just a course to help the mathematics students get to grips with using programming to solve mathematical problems but for the CS students, it really just gives us a chance to do some extra work.

My issue is with my lack of knowledge surrounding algebraic structures / theory, mostly due to the interruption of teaching because of COVID. I don’t totally understand your reasoning for why I can argue that most non-primes can be ruled out, nor do I totally understand RayMan’s reasoning behind why our set of “good numbers” must be of a certain form - and I don’t want to use anything I haven’t properly understood as this just seems wrong.

It’s also why I keep thanking the both of you since you have provided discussion beyond what I can currently comprehend and I do feel a level of guilt that I cannot totally grasp it.

Also, in practice your program should run more or less OK even for “medium” values of n. For example, I just tried n=10^{60}, and after a few seconds we see that

m = 999999999999999999999999999999999999999999999999999999999829

is a “full prime”, at which point we can obviously stop.

Yeah - the program in reality should never take too long, it was more just my personal task of making it as quick as possible.

We are tasked with using Matlab but using python I have attempted the issue with far larger numbers, and we can see from your choice of “medium” n = 10^{60}, and my explanation of the biggest n we will test the true reality of the task.

I did some more testing of the graph I produced and expanded my set of denominators up to 20000.
This is the result:

Are these lines of orange points that appear a consequence of Artin’s conjecture that you both mention?

Aren’t those just straight lines with slope 1, 1/2, 1/3, and so on?

No idea, I’m just asking - just fascinated me that it so many occurred in a straight line together so densely.

I came up with another question which I hope you guys could entertain; if my task was simply to eliminate possibilities, forgetting about actually determining the best number (from the set of “good numbers”), is the best and possibly only way to do it as @RayMan suggests and only considering m such that m=p^k?

I know this was said

but did you discover this proof in some other literature? Are you able to point me there? Could you even help with regards to a non rigorous proof or any thing that I could really use to justify my reasoning as to why I will disregard all numbers not of the form p^k?

You two post faster than I can prove theorems in algebra – which, as @DPRK has illustrated, is an ability I may have lost. (No joke, thanks for the feedback @DPRK, I’ve been wrong several times now).

There’s a lot going on here. In an attempt not to embarrass myself further, I shall now differentiate between theorems that have been proven true, and claims I make which I have not yet proven.

Definition: let a, k \in \mathbb{N}, a > 1, k>1, and let p be a prime such that \gcd(a, p)=1. We say that a is a k-th power residue modulo p if there exists b \in \mathbb{Z} such that b^k \equiv a (mod p). If a is not a k-th power residue modulo p, we say that a is a k-th power nonresidue modulo p.

It is a theorem that a is a primitive root modulo a prime p if and only if a is a q-th power nonresidue modulo p for every prime q dividing p-1. I claim that those lines that you see are in fact lines with slope 1/2, 1/3, 1/5, 1/7, … , 1/q for q prime (but I also claim that not every prime lies on such a line, more on this later). We know (that is, it is a theorem proven by an individual that is not myself) that the decimal representation of \frac{1}{p}, p prime has period \mbox{ord}_p(10), that \mbox{ord}_p(10) \mid \phi(p)=p-1, and that if \mbox{ord}_p(10)=p-1 then 10 is a primitive root modulo p by definition.

So, the red line at the top is the set of full reptend primes, which means that it is the set of all primes p such that 10 is a q-th power nonresidue for every prime q dividing p-1. I claim that the first orange line is the set of all primes p such that 10 is a quadratic residue modulo p, and 10 is a q-th power nonresidue for every prime q \neq 2 dividing p-1. I claim that the second orange line is the set of all primes p such that 10 is a cubic residue modulo p, and 10 is a q-th power nonresidue modulo p for every prime q \neq 3 dividing p-1. I claim that the third orange line (if one can make it out, things get hazy there at the bottom) is the set of all primes p such that 10 is a quintic residue modulo p and 10 is a quintic nonresidue modulo p for every prime q \neq 5 dividing p-1, and so on, for every prime q.

From here on out, let p and q always denote a prime, it makes things easier. It is a theorem that if a is a q-th power residue modulo p with q \mid p-1, then \mbox{ord}_p(a) \leq \frac{p-1}{q}. Furthermore, if 10 is a q-th power redisue modulo exactly one q \mid p-1, then \mbox{ord}_p(10)=\frac{p-1}{q}. (Personal claim now:) That is why those lines have slopes that are the reciprocals of primes. Remember, each of those points has coordinates (p, \mbox{ord}_p(10)). If we, say, consider the first orange line, these points have coordinates (p, \frac{p-1}{2}). These points lie on a line of slope 1/2, and so on for the remaining orange lines for all the primes q. The top red line consists of points (p, p-1), and so has slope 1.

However, I claim that not every prime lies on such a line. From the way we have defined those lines, if 10 is sumultaneously a q_1-th power residue modulo p and a q_2-th power residue modulo p, then p will not lie on any of those lines. They’ll be kind of an intermediate orange fuzz (no, not standard terminology).

That those lines are so clear and so solid is something of an artifact of the fact that your graph only shows tiny, tiny, tiny primes. (The lines are real, this is a real result, it’s just that things get more complicated.) As the upper bound for the x-axis approaches infinity, several things will start to happen. First, the primes become more sparse in \mathbb{N} as you consider larger primes. Your line will look like a dotted line, and eventually there will be points on a given line arbitrarily far apart.

Even beyond that fact, the line with slope 1/2 will look fuller than the line with slope 1/3 will look fuller than the line with slope 1/5, and so on. This is because “elementary” k-th power reciprocity theory is actually governed by rather deep algebraic phenomena: the splitting/ramification behavior of prime ideals sitting above p in algebraic number fields. That theory is a little bit too complicated to go into here, but in some very well defined sense (in the sense of a density statement given by the Chebotarev Density Theorem), for every q \mid p-1, \frac{1}{q} th of the p-1 incongruent residue classes modulo p are q-th power residues modulo p. So, in the sense described, the lines with slope \frac{1}{q} must be getting “sparser” as q increases.

Also, 2 \mid p-1 for every p, while only finitely many other primes divide p-1, and so, in some sense, 10 has a greater “chance” of being a quadratic residue modulo p than any other q th power residue modulo p for q \mid p-1. I use the word “chance” as an analytic number theorist does; these phenomena are deterministic, not probabilistic, that’s just how they roll. The number, on average, of distinct prime divisors of an integer n grows very very slowly as n does, so for small primes (however you want to define small), it can’t be a q-th power residue modulo p for very many q's.

And, finally, we come to perhaps the biggest issue if we seek a general theorem for identifying our “good numbers.” There is no getting around it. Or, perhaps one should say, if you get around it you will be a millionaire and the most famous number theorist on the planet: It is not currently known whether there exist infinitely many primes p such that 10 is a primitive root modulo p. Period. The infinitude has been proven under the assumption of a generalized Riemann Hypothesis (this is Artin’s Conjecture on Primitive Roots), which is believed by most to be true, but no one has proven it. So not only will that red line get sparser and sparser, for all we know, it may eventually stop. . .

Thanks, @RayMan.

I agree, I’m posting too much too fast but that’s just my erratic student nature just getting everything I have in my brain out in text.

My knowledge of this small section of number theory is slowly improving I feel as each time you post I’m able to understand what you’re saying a little easier and with less effort.

I understand everything from your last post (at least I think so) but I can’t seem to connect it with

As mentioned I’ve been able to construct my report to the point where I’m now just figuring out how I can justify reducing my list of possible ‘good numbers’.

We’ve all spoken about how there’s not much more we can reduce the problem by but I feel for how small my problem currently is just justifying this would be a huge step.

On a side note, thanks for how clearly you’re able to communicate your knowledge via text; it’s made it really easy for me to understand :slight_smile:

You’re very kind; I’m certain my ability to communicate my knowledge, such as it is, has at times been poor or downright incorrect. But I think that’s often how real math is done: you’re wrong a couple of times, you bounce ideas off your colleagues, you correct all your mistakes, and you write it up all nice and neat and perfect.

Let’s keep this short: I’m not confident that in identifying what we have termed good numbers, one can ignore numbers other than prime powers. I would not be surprised if you eventually found a counterexample if you looked at larger moduli. What you’re essentially looking at is the order of the cyclic subgroup generated by 10 in \mathbb{Z}/m\mathbb{Z}^\times, where \gcd(10, m)=1. I know of no a priori way to calculate the order of this group. When the order of this group is equal to \phi(m), the group is as big as it can be, by Lagrange’s Theorem and others (I called this “maximal” in an earlier post, and @DPRK rightly pointed out that this usage was ambiguous; it is not “maximal” in the sense that it must necessarily be a good number: there may be a prime p'<p such that \mbox{ord}_{p'}(10)>\mbox{ord}_p(10)).

In order to keep this short, I will stop for now, and add a little bit more once I’ve had a chance to think. In the meantime, those blue points (composite numbers) in your graph that lie above the line with slope 1/2 that we talked about: is it possible to verify whether they are all prime powers? Please don’t spend too much time on this if you are otherwise busy. I’m just some dude on the internet. But it would be interesting to see if they are all prime powers. It proves nothing, of course!

Well, the other way around, really.

While analysing your algorithm’s running time is crucial, you make it sound as though in your application n is never going to be very big. It will be smaller than 10^{100}, let’s say. So you can just do something like: compute the multiplicative order of 10 modulo m (after casting out 2’s and 5’s), subtract 1, repeat. “Soon enough” you will find one with order m-1 so you can stop and print out the one that gave you the maximum value.

Certainly the “blue points” are arranged into their own lines. E.g. 10 is a primitive root not only modulo 7 and 19 but modulo 7^k and 19^k for any k\ge1.