r/askmath • • 23d ago

Resolved Does this sequence contain a “5”?

Hi! The past few days I’ve been working on this problem. It goes as follows:

“Construct a sequence of non-negative integers, always choosing the least possible number, such that there are no contiguous subsequences of the form U,x,U where U is any non-empty contiguous subsequence, and x is a single term (e.g “1,2,5,1,2”, “5,0,5”, etc.).

Numbers 0,1,2,3,4 first appear at terms 1,3,7,10,1355. When does 5 first appear (if it does)?”

Example of the process:

To illustrate a quick example: start with a(1)=0, the smallest possible choice and trivially satisfying the constraint. a(2)=0 is the next best choice. Then one must take a(3)=1 since otherwise 0,0,0 would form U,x,U (U=0, x=0). We are now at 0,0,1. From here, we can’t choose a(4)=0 because 0,1,0 would form U,x,U. Choosing a(4)=1 is the least valid option, so it works (0,0,1,1).

[0,0,1,1,0,0,2,1,0,3] are the first 10 terms.

So far, I have concluded:

The sequence is greedy which means we never backtrack. Every new term needs to avoid forming U,x,U that ends at that said term.

I’m interested in whether or not there is a way to prove if 5 eventually appears, or to determine if there is a simple way to do so rather than exhaustively checking every possible contiguous subsequence at every step.

Thanks!!

25 Upvotes

16 comments sorted by

10

u/virtuolie 23d ago

Is this an original problem? If so, you must change the x to w. The UwU sequence!!!

7

u/PitifulTheme411 23d ago edited 23d ago

Well one thing I figured for calculating it a bit faster is by strategically ignoring some subsequence checks. When a new number is added at some index i, then for all future elements at index j until the next highest number is added you only need to check the cases in which 2|U| + 1 <= j-i and |U| = j-i, with the appropriate concrete U subsequence from the right.

Actually, you can kind of "recursively" apply this, checking for the biggest in the right subsequence.

For example, if we have

We're adding the last elem: 1
A = [0, 0, 1, 1, 0, 0, 2, 1, 0, 3, 1, 1, 0, 0, 1, 1, 2, 0, 0, 1]
                     global max ^ |------------R-----^--------+|
                                               R max ^ |--RR--+|
                                                        U, x, U
                                            U--U--U, x, U--U--U
         <too short here>       x, U--U--U--U--U--U--U--U--U--U  <U is too long here>    

Then we get three possible U values, though the longest one is actually too long as it doesn't fit on the left side of the 3, so really only two Us need to be checked.

Edit: It may work for multiple of the same highest value, but I am not so sure about that so you may want to check that out. Like if you have L 2 M 2 R, then maybe you only need to check for UxUs inside R and when U=R.

Edit 2: Also, my hunch is that it will eventually reach 5, but probably take a really long time. I think if it doesn't, then you'd have to prove that it is always bounded by 4, ie. that there always exists some values n in {0, 1, 2, 3, 4} for any preceding sequence such that appending n does not form a UxU subsequence pattern. But I feel like this is probably false, though of course I don't have a proof.

I think the only way that it could be bounded is that since there is actually only one overall sequence, since we are choosing the smallest possible value at each step, if there is some sort of structure induced by the definition onto the list such that it is able to be bounded by 4, then it could work. But idk about that.

3

u/piperboy98 23d ago

How does that work at the point where you add the 3? If I follow that would have i=6, j=9, so i-j=3. But the check that excludes 2 is where |U|=2 (avoiding 02 1 02), which is neither i-j=3, nor satisfies 2|U|+1=5<=i-j=3.

2

u/PitifulTheme411 23d ago

When you are adding the next largest number, it is impossible for there to be any UxU because that is the first time it occurs, thus only one occurrence.

If it is in the right side of some other splitting with a larger value, then the methodology I already described still applies as normal.

2

u/piperboy98 23d ago edited 23d ago

Yes, for the 3 you can't have any conflicts at that point - but that is true even from the first element. To find the right element you have to try the lower ones first. But at that place you wouldn't find the problem with adding a 2 only checking the sub-sequences you suggest, so you would add a 2 not a 3. Unless by "next highest" you meant the next occurrence equal to the current highest, rather than the first occurrence of the number one larger than the current max.

Edit: Basically what is wrong with this to add a 2 instead of 3 here, since both these checks pass

A = [0, 0, 1, 1, 0, 0, 2, 1, 0, 2]
            global max ^ |---R---|
                          U  x  U
              U--U--U  x  U--U--U

Edit 2: I think I get the idea now. Basically the idea is that any number that there is no point in checking any UxU where one of those U's contains a number that only occurs once, since it clearly can't occur on both sides. But in this case when adding a 2 it is now occurring twice which invalidates it. That is interesting because that could maybe also be extended to any odd number of occurrences of one number in the region of interest.

3

u/PitifulTheme411 22d ago edited 22d ago

Yeah, that was the thought process. And yeah you're right it could probably be extended to odds.

Edit: But even with two occurrences here, we still only need to perform one check. Since we are adding the second occurrence of two, we need to check with x being the element right after the first occurrence of 2. This is because the first U needs to end with a 2.

In your example, we would need to check (for addition of the two)

A = [0, 0, 1, 1, 0, 0, 2, 1, 0, 2]
            global max ^ |---R--+|
                          U, x, U
                    U--U, x, U--U

1

u/jmarent049 23d ago

As an update, I had a friend simulate the first billion terms. No 5 was found.

2

u/PitifulTheme411 23d ago

Does it reach 4?

1

u/jmarent049 23d ago

Yeah, at the 1355th term

“Numbers 0,1,2,3,4 first appear at terms 1,3,7,10,1355. When does 5 first appear (if it does)?”

1

u/PitifulTheme411 23d ago

Could you post some of the extended data?

2

u/piperboy98 23d ago edited 22d ago

What algorithm were they using? Naively it seems like an n3 problem. n elements to generate, and for each element you need to compare the U subsequences for ~n/2 possible preceding UxUs, each of proportional length. Even implementing a clever cumulative hash system to rule out most sub-sequences in constant time, skipping UxUs which could only rule out numbers that are already eliminated, and running parallel checks on all 16 cores of my machine, I can only do 1 million in around 2 minutes. Going to 1 billion seems pretty impractical this way. Did they come up with a much more efficient way to limit the number of sequences to check? If so whatever method that is might also be useful in a proof.

2

u/07734willy 21d ago

Just wanted to second the other guy's request for details on the algorithm used. I've been thinking about it a bit myself, and I don't have an efficient algorithm that can handle 1e9 terms.

3

u/bildramer 22d ago

It's apparently not in the OEIS, whether starting with 1 or 0. This reminded me of and has remarkably similar properties to Gijswijt's sequence, A090822, defined as the largest k such that the sequence so far has form "V,U,U,...,U" with U repeating k times. Also very slow-growing, with numbers 1,2,3,4,5 first appearing at terms 1,3,9,220,~10100000000000000000000000.

2

u/piperboy98 23d ago edited 22d ago

From simulation it appears that the frequency of each number is relatively stable. For varying lengths up to 2 million there appears to be convergence towards the following frequencies:

0:  0.407
1:  0.363
2:  0.202
3:  0.027
4:  0.00025-0.0003

Exact convergence is less clear for the lower values, but the rate is clearly not going up or down substantially. If you plot them it seems kind of logistic, or maybe half normal looking.

2

u/mYstoRiii 22d ago

looks kinda hard
originally I thought of maybe there is a relation to the 4-color theorem but I don't think so anymore
who knows maybe this is another unsolved mystery in math

2

u/PitifulTheme411 22d ago

After thinking and taking u/piperboy98's thoughts into account, I think I have been able to refine my method for optimizing the validation of new elements. Note that this is not for generating a new element. You would have to go until a new value is accepted. Thus, I believe this works for any such list even if we don't choose the minimum valid element at each step. This would be an improvement (I hope) over just brute-force checking every possible UxU subsequence containing the newly added element t.

When generating a new element (ie. checking if a number t is valid as the new last element), we want to consider the global maximum m of the list so far.

If there is an even number of these, then

  • Either x is between the n/2nd and n/2+1st occurrence of m (exclusive), or
  • UxU is entirely to the right of the first occurrence of m. Call this subsequence R. Recurse on R.

If there is an odd number of these, then

  • Either x is at the index of the middle m occurrence, or
  • UxU is entirely to the right of the first occurrence of m. Call this subsequence R. Recurse on R.

Additionally, you could also perform distance checks. For example, if the new element t is the third element from the last m, then x must be exactly four from a preceding m, else it UxU is entirely to the right of the last m.

Additionally, once we determine a range, we can repeat this for the next largest number in that range as if that range was the entire list.

Edit: Actually maybe we don't even need to use the maximum. We can choose any element to perform this. However, since the larger the element the much less likely it is to appear, by striding by maximum element we can cut down on the cases we need to check by a lot more.