In the best repeating patterns of prime length, sums repeat a color half as often as at random
Why it matters
Suppose you color numbers in a repeating pattern and want two numbers and their sum to have three different colors. With many colors and a prime pattern length, the best designs produce about half as many repeats as coloring at random. They work by making the sum likely to match both numbers whenever those numbers already share a color.
Suppose each positive integer has a color. How often can two numbers and their sum have three different colors? With independent random choices from k equally likely colors, about 3/k of sums of distinct addends repeat a color when k is large. Choosing the colors deliberately can help. The difficulty is that a choice that works for one sum also affects every other sum involving that number.
For a coloring that repeats after a prime number of positions, we find that the smallest possible fraction of sums with a repeated color is 3/(2k) to first order, half the random rate. We allow the prime to vary with the palette. Our patterns approach this rate by concentrating color matches in the same sums. When both addends have the same color, their sum has that color nearly three quarters of the time.
Counting sums on an interval and in a repeating pattern
Call a sum x+y=z rainbow if the three numbers have distinct colors, and a failure if a color repeats. On the interval from 1 to n, count all ordered pairs of positive integers with x+y\le n. Hegde, Kumar and Pratibha, Theorem 1.3 showed that as n tends to infinity, at least a fraction 1/k must fail. They constructed colorings with failure fraction at most 1-(k-2)(k+1)/((k-1)(k+3)), whose leading term is 3/k. These bounds leave open even the leading coefficient for large palettes.
In a pattern of length p, an integer's color depends only on its remainder, or residue, after division by p. To score a pattern c, take all p^2 ordered pairs of residues (x,y), including zero and equal addends, and reduce their sum to its remainder as well. Let F(c) be the fraction of these pairs that fail. Let D_k be the infimum of this fraction (its greatest lower bound) over all prime periods p and all patterns using at most k colors. Our result is
Why some color matches are unavoidable
A color class A is the set of residues with one color. If it has size a, there are a^2 ordered pairs whose addends both lie in A. There are also a^2 pairs whose first addend and sum lie in A: specifying those two residues determines the other addend. The same count holds for the second addend and the sum. Adding the three counts counts a failure once if just two positions match in color, but three times if all three match. Let T(A) count the ordered pairs in A whose sum is also in A. Subtracting the two extra counts gives
A short interval centered at zero keeps about three quarters of its sums inside. Huczynska, Jedwab and Johnson give the maximum internal count for a single set of a given size. For a coloring, we also use the fact that only one class can contain zero. This matters especially when many classes are small.
To count the sums that stay inside A, write x+y=z as z-y=x. Let r(d) count the ordered pairs (z,y) in A with difference d, so T(A)=\sum_{d\in A}r(d). Suppose a\le p/2. Set t=\lfloor a/2\rfloor, rounding down to a whole number. Pollard's inequality gives a lower bound on the total when each difference counts at most t times. Applied to A and the set of its negatives, -A, it gives
Since t(a-t)=\lfloor a^2/4\rfloor, the class containing zero contributes at least 3a^2/2-1/2 to the failure count. Every other class contributes at least 3a^2/2+a: the extra 2(a-t) in its failure count covers the rounding loss even for odd a. Write a_0 for the size of the class containing zero. If no class exceeds half the period, adding these bounds gives
We checked the bound on T(A) by counting internal sums for every nonempty subset of size at most half the period for primes through 19. All passed, including 262,143 subsets at period 19 alone. The same check found three violations at period 8 and 35 at period 16. Thus the bound for a single class can fail at composite periods.
Building a pattern from copies of one class
Start with the positive and negative digits up to a half-width h, leaving out zero: S_h=\{-h,\ldots,-1,1,\ldots,h\}. Multiplying every digit by the same nonzero residue preserves its internal sums modulo a prime p. This gives a way to make classes with identical sum counts. For example, modulo 13 the three sets S_2, 3S_2 and 4S_2 cover the twelve nonzero residues exactly once. Giving each set its own color and adding zero to any one of them completes the pattern.
Blackburn and McKee, Proposition 7.1 gave a test for when such copies tile the nonzero residues, meaning they cover them without overlap. The test requires that 2h divide p-1 and that the powers j^{(p-1)/h} for 1\le j\le h have distinct remainders modulo p.
To see why the test works, let H contain the nonzero residues whose power with that exponent equals 1 modulo p. The nonzero residues form a cyclic group under multiplication: they are all powers of one residue. It follows that H has size (p-1)/h. It contains -1 because the exponent is even. In each set jH (all products of j with elements of H), every element has the same power as j. The distinct powers therefore keep the sets jH disjoint, and together they cover the nonzero residues. Now take one multiplier u from each pair \{u,-u\} in H. The digits in uS_h pick out both ju and -ju in each jH. This gives m=(p-1)/(2h) disjoint copies uS_h, each with its own color.
For p>3h, ordinary addition suffices to count internal sums: for three signed digits, x+y-z is too small in absolute value to be a nonzero multiple of p. Among ordered pairs with the same sign, h(h-1) have their sum in S_h, counting both signs. Among opposite signs, only exact cancellations fail to stay inside, leaving 2h(h-1) internal sums. The fraction internal is therefore 3h(h-1)/(2h)^2, which tends to three quarters. Each class contributes 3(2h)^2-2\cdot3h(h-1)=6h(h+1) failures. Adding zero to one class creates 4h internal sums with exactly one zero addend, 2h cancellations and the all-zero pair. In the match count 3a^2-2T(A) these changes increase the total by just one failure. The complete pattern has failure fraction
Counts for finite patterns
An exhaustive search of partitions for periods 2 through 17 found copies of S_2 in an optimal four-color pattern modulo 17. We tested half-widths 1 through 64 against the first 10,000 primes, through 104,729. Of the 56,191 width–prime pairs for which 2h divides p-1, 13,888 passed the distinct-powers test. We excluded 30 with p\le3h, where reducing sums modulo p can change the digit count. At half-width 11, only two primes gave usable tilings. At the larger prime, multiplying the failure fraction by the number of colors gave mF=1.63632, compared with the limiting target of 1.5.
Table 1. Tilings at selected half-widths. Eligible primes satisfy the divisibility requirement; usable tilings also pass the power test and have p>3h. The color count and scaled failure fraction are for the largest usable prime at each width. A zero means the test found no usable tiling in this scan.
| Half-width h | Eligible primes | Usable tilings | Largest usable p | Colors used | Scaled fraction mF |
|---|---|---|---|---|---|
| 1 | 9,999 | 9,998 | 104,729 | 52,364 | 2.99995 |
| 2 | 4,984 | 2,497 | 104,717 | 26,179 | 2.24996 |
| 4 | 2,486 | 0 | — | — | — |
| 5 | 2,484 | 150 | 104,231 | 10,423 | 1.79997 |
| 11 | 990 | 2 | 78,541 | 3,570 | 1.63632 |
| 14 | 821 | 0 | — | — | — |
We checked coverage and counted internal sums on the classes themselves for every usable case through period 257 and for the largest usable prime at each successful width, 81 partitions in all. At h=14, the only prime in the scan that passed the power test was 29, too small for the digit count. Extending the search at that width gave p=434{,}029. Its 15,501 classes use the multipliers 6^{14i} for 0\le i<15{,}501, with zero in the first class. An independent count confirmed that each residue appeared exactly once. It found 12,152,841 failures where the addends had the same color. When the addends differed in color, the sum matched the first in 3,689,210 pairs and the second in another 3,689,210. That gives 19,531,261 failures in 188,381,172,841 pairs, or mF=1.60714.
Reaching the bound for every large palette
A tiling must use nearly all the available colors to give the desired rate for a specified palette size k. Widely spaced examples could leave gaps. For each fixed h with 2h+1 prime, Blackburn and McKee, Theorems 7.2 and 8.1 give the frequency of primes that pass the test. Their count up to X, divided by c_h X/\log X, tends to one for a positive constant c_h. Comparing counts at X and (1-\epsilon)X puts a passing prime between them for every fixed 0<\epsilon<1 and all sufficiently large X.
Choose the largest passing prime at most 2hk+1. Its tiling uses m\le k colors, and m/k\to1 as k grows with h fixed. Eventually p>3h, so the exact failure fraction gives the following upper limit:
What the patterns give on an integer interval
Repeat a fixed pattern of prime length p on the integers from 1 to n. The ordered pairs to count lie in the triangle x,y\ge1, x+y\le n. Each complete p-by-p block contains every ordered residue pair once. The partial blocks at the boundary contribute only O_p(n) points, a count that grows at most linearly in n for fixed p. Thus the interval failure fraction tends to the pattern's fraction F as n grows.
Taking interval length to infinity before palette size, these patterns halve the leading 3/k loss in the earlier interval construction. The matching lower bound relies on the uniform counts for each pair of positions over a prime period. Whether unrestricted interval colorings can improve on 3/(2k) remains open.