The extra bits needed to tell two patterns apart by counting can grow in proportion to pattern length
Why it matters
Count how many ways a bit pattern appears in each longer string, then forget which count belongs to which string. Two patterns of 401 bits give identical counts when grouped this way at every length through 423 bits, but differ at 424. The number of extra bits needed can grow in proportion to the pattern length, though the proof guarantees a tie for only one extra bit per 32,768 pattern bits.
How long a string of zeros and ones do we need to tell two patterns apart by counting? A pattern occurs as a subsequence of a string (its host) whenever we can read it from left to right, skipping letters if needed. For example, 01 occurs twice in 001: either zero can pair with the final one. At each host length, we can count how many strings contain the pattern exactly once, exactly twice, and so on, including how many never contain it. This histogram discards the identities of the hosts. Two patterns can therefore give the same histogram even when they occur in different strings. If the histograms keep agreeing as we increase the host length, when is it safe to stop?
Two patterns of length 401 have identical histograms at every host length through 423 and first differ at 424. The delay can grow in proportion to the pattern length. For every prime length k\ge5, we construct a pair whose histograms agree through at least \lfloor k/32768\rfloor extra letters (rounding down to a whole number) but differ somewhere by length 2k-1. Thus a test that checks every length starting at k can miss a difference even if the number of extra letters it checks grows with k, whenever that growth is sublinear.
What makes two patterns hard to distinguish?
Each choice of positions spelling the pattern is called an embedding. At host length n, the histogram entry for count c is the number of the 2^n hosts with exactly c embeddings. At the pattern's own length, only one host contains it, so all patterns of that length have the same histogram.
Menon and Singh [1] call two patterns strongly Wilf-equivalent if their histograms agree at every length. Reversing a pattern or exchanging its zeros and ones preserves every histogram: the same operation simply permutes the hosts. Menon and Singh conjectured that these symmetries account for all equivalences. They verified this through pattern length 13 with the mathematics software Sage, without specifying a host-length cutoff. Here the patterns are inequivalent. The excess is the number of extra host letters. The first differing excess is the length of the shortest host at which the histograms differ, minus the pattern length.
Moving one feature within a repeating pattern can delay the first difference. For example, counting hosts by inserting extra letters into the patterns (see the enumeration method in [2]) gave pairs of lengths 12 and 76 whose histograms agreed through three and seven extra letters, respectively.
Two positions for a marker
Take four copies of the same block U of m bits. Choose U to be a palindrome (it reads the same in both directions) containing at least one 1. Insert a marker M=0^r, a string of r zeros, either in the middle or after the first block. Call the resulting patterns P and Q:
Theorem 1. For every prime k\ge5, write k=4m+r with r\in\{1,3\}. There exists such a block U for which the two length-k patterns have the same histogram at every host length from k through k+\lfloor k/32768\rfloor. Their histograms differ at some length at most 2k-1. The guaranteed number of extra letters with equal histograms becomes positive for k\ge32768.
To see why the marker's position is hard to detect, slide a window of length at most m along each pattern. Every string that fills the window (a contiguous substring, or factor) occurs equally often in P and Q. Inserting the marker removes windows that cross the insertion point and adds windows that touch the marker. Both insertion points have the same m letters on either side, so the changes are identical.
An embedding can reach beyond a window by skipping letters. The proof below shows that, for a suitable U, the frequencies of factors of length at most m still determine the whole histogram when there are few extra letters. The eventual difference comes from a property of the whole pattern: P is a palindrome and Q is not.
First differences for seven pairs
Table 1 gives the exact first differences for seven selected block lengths from 3 to 100, each with a single-zero marker and prime k=4m+1. To fix one block of each length before calculating the thresholds, we used SHAKE256, a function that converts a specified input into a reproducible stream of bytes. The input was “block:” followed by the block length written in decimal. The low bit of each successive byte supplied one letter of the first half of U, including the center for odd lengths. We reflected those bits to complete the block, without searching over seeds.
For all seven pairs, the first excess at which the factor frequencies permit a difference is where the histograms separate. To see a difference it suffices to square the embedding count in each host and sum over hosts: identical histograms must give identical sums. For the length-401 pair, the full distributions agree over all 2^{423} hosts of length 423. At length 424 the sum for P is smaller than the sum for Q by 104,599,040,800.
Table 1. Each row specifies a pair with a single-zero marker. Read the hexadecimal (base-sixteen) entry as a binary integer, padding it on the left with zeros to \lceil m/2\rceil bits to recover the first half of U. Reflection supplies the rest. The final column gives the sum of squared counts for P minus the sum for Q at the first differing length.
| Pattern length | Block length | Left half of block (hex) | First differing excess | Difference in sums of squared counts |
|---|---|---|---|---|
| 13 | 3 | 3 | 1 | -18 |
| 29 | 7 | C | 3 | -8 |
| 61 | 15 | CB | 5 | -72 |
| 101 | 25 | 159F | 6 | 192 |
| 193 | 48 | 929646 | 9 | 72,576 |
| 313 | 78 | 72577FE190 | 14 | -14,112 |
| 401 | 100 | 10261A4FDF203 | 23 | -104,599,040,800 |
Why short factors determine the histogram
Instead of counting hosts with each possible number of embeddings separately, count groups of embeddings in the same host. Fix a length-k pattern w and a positive integer h. A host with c embeddings gives c^h ordered choices of h embeddings, allowing repetitions. The sum of these counts over hosts is the raw moment of order h. Delete all host positions unused by the chosen embeddings. Let A_{h,j}(w) count the resulting ordered groups (tuples), together with their reduced hosts, of length k+j. To restore a host of length n, choose the positions occupied by the reduced host and freely fill the unused positions. The raw moment is therefore
Lemma 1. Each reduced tuple has a unique division into pieces
Think of an embedding as a path through the pattern. At each host position it either advances by reading the next pattern letter or stays put. After each position, record how far every path has advanced. Cut wherever all paths have read the same number of letters. Between consecutive cuts, the paths consume the same interval I of l pattern letters. If they use l+e host positions to do so, each path skips exactly e. When e=0, the piece is a single site read by all paths: otherwise there would be an interior cut.
For a nonempty interval I, form the polynomial a_I(z) whose coefficient of z^e counts reduced pieces on I with no interior cut and positive excess e. Its constant coefficient is zero. Even when |I|=1, a piece can have positive excess if the paths read that letter at different host positions. The weight a_I depends only on the letters on I.
Conversely, choose any collection \mathcal S of pairwise disjoint intervals, allowing adjacent intervals. Fill each with a positive-excess piece and fill the remaining sites with single steps taken together. This reconstructs the tuple, and the cuts recover the chosen pieces uniquely. Thus
Lemma 2. Taking the logarithm isolates connected intervals
Call a collection connected if each interval can reach every other by a chain of intervals sharing sites. Only connected collections contribute to the formal logarithm of Z_w. This is the connected-support property of the cluster expansion [4], a way of expressing a logarithm as a sum of connected contributions.
To see why, temporarily replace each weight by a separate variable x_I. To find the coefficient of any product of variables in the logarithm, we may set all other variables to zero. If the intervals in the product split into two groups with no overlap between groups, the sum over disjoint collections factors into a sum for each group multiplied together. Its logarithm is the sum of their logarithms, so the mixed product has coefficient zero. The argument allows repeated powers of the same variable. Substituting the weights back is valid degree by degree because they have zero constant term.
The union of connected intervals is itself one interval. The total contribution from configurations with exactly that union depends only on the factor it contains. Reversing all paths or flipping all bits preserves the contribution. Let N_w(u) count occurrences of factor u and let G_{h,d}(u) collect the contributions through degree d whose union is exactly one copy of u. Ignoring powers higher than d gives
When this holds for every h, the histograms agree. At fixed host length, the possible embedding counts lie in a finite integer range. Polynomial interpolation gives a polynomial equal to one at any chosen count and zero at all the others. Summing its values over hosts recovers that histogram entry from the moments, including the common zeroth moment 2^n.
Lemma 3. Two paths bound the excess needed to span an interval
For an interval of length l, write down two strictly increasing lists of positions in it. Match the lists in order, requiring each pair i,j to have equal letters and i<j. Define the cost of the interval as l minus the largest possible number of pairs. The cost is at least one because the last position cannot appear in the first list. A constant interval of any length has cost one: match each letter except the last to its successor.
Every positive-excess piece on the interval has excess at least its cost, however many paths it contains. To prove this, track the least and the greatest progress among the paths after each host position. Each of these two records is itself a valid path: an increase from i to i+1 requires some path to take that step. The two records differ at every interior time because the piece has no interior cut. Each reads l letters on l+e sites, so at least l-e sites are used by both. At those sites they read equal letters at strictly ordered pattern indices: advancing together from equal indices would keep them equal, impossible in an uncut piece of positive excess. The two lists of indices increase strictly. Their matching shows that the cost is at most e.
Any term of degree at most d in the logarithm therefore comes from connected intervals of total cost at most d. Such ordered self-matchings also occur in synchronization codes, which deal with insertions and deletions [3]. Here the matching bounds how far paths can travel out of step.
Choosing a block that keeps connected intervals short
Lemma 4. A palindrome can have few intervals that are long for their cost
Put C=4096. Call an interval cheap if its length l exceeds C times its cost. For every m\ge1 and r\in\{1,3\}, there exists a palindromic block U containing a one for which the sum of the lengths of all cheap intervals in P and Q together is less than m/4.
Choose the first \lceil m/2\rceil letters of U independently, each equally likely to be zero or one, and reflect them to complete U. Consider a particular interval in either pattern. Cheapness requires l>C and an ordered self-matching of size l-q, where q=\lfloor l/C\rfloor: we can drop any surplus pairs. There are at most \binom lq^2 choices for the two lists. Since each omits only q positions, the two indices in each pair i<j differ by at most q<m.
At most 2r\le6 pairs touch the marker. Discard them, remove the marker and number the remaining positions in the four copies of U from 0 through 4m-1. Within each surviving pair the indices remain distinct and less than m apart, so they cannot be equal modulo m. They can refer to the same random bit only by reflection, when their sum equals m-1 modulo m. The sums increase strictly along the matching and lie between 0 and 8m-2, so at most eight pairs qualify.
That leaves at least l-q-14 required equalities between distinct random bits, counting repetitions. Draw a vertex for each bit and an edge for each equality, allowing multiple edges. A vertex has degree at most 16: its bit occurs at most eight times in the four blocks, and each occurrence is used at most once on each side of the matching. A connected component of v\ge2 vertices forces all its bits to agree. It imposes v-1 independent equalities and has at most 8v\le16(v-1) edges. The probability that the specified matching works is therefore at most 2^{-(l-q-14)/16}.
For l>C, the exponent (l-q-14)/16 exceeds l/17. The number of choices satisfies \binom lq^2\le (\mathrm e l/q)^{2q}\le 2^{l/128} because x\log(\mathrm e/x) increases for 0<x<1. Summing over choices bounds the probability that the interval is cheap by 2^{-l/32}.
At each length there are at most 2k intervals in the two patterns. The expected sum of cheap lengths is at most
For such a block, take any connected cover of total cost at most d=\lfloor m/(2C)\rfloor. Intervals that are not cheap cover at most Cd\le m/2 sites. Cheap intervals together cover less than m/4 sites, regardless of repetitions. The union thus has length less than m. Since P and Q have the same factor frequencies through length m, Lemmas 1–3 give equal histograms through excess d. With k=4m+r and r<4, this is \lfloor k/32768\rfloor extra letters, proving the equality in Theorem 1.
Why the histograms eventually differ
Lemma 5. At prime length the second moment detects reflection symmetry
For any odd prime pattern length k, a palindrome and a nonpalindrome have different sums of squared embedding counts at some host length no greater than 2k-1.
Consider the reduced count A_{2,k-1}(w) for a length-k pattern w. Two embeddings that together use 2k-1 sites must share exactly one site. Number pattern positions starting at zero. If the shared site reads positions i,j in the two embeddings, their letters must agree. Interleave the prefixes before that site and then the suffixes after it. Counting the choices gives
The remainder of A_{2,k-1}(w) upon division by k thus equals the number of positions where w agrees with its reversal, taken modulo k. A palindrome has k agreements. A nonpalindrome has fewer than k but at least the middle agreement. Their remainders differ. In the formula restoring unused positions, each new reduced coefficient enters with multiplier one and the other terms use only earlier coefficients. Hence some raw second moment must differ by length 2k-1.
In our pair, P is a palindrome. If Q equaled its reversal, canceling an outer U from each side of that identity would give 0^r U^2=U^2 0^r, where U^2 denotes two copies of U. The first one occurs later on the left. Thus Q is not a palindrome, and Lemma 5 proves the separation in Theorem 1.
Calculating the exact thresholds in Table 1
For each pair, we first found the smallest excess at which the local factor argument permits a difference. We computed every factor's cost by finding its largest ordered self-matching. For two prefixes of the factor, the best matching either drops the last letter on one side or pairs the two last letters if they agree and their positions are strictly ordered. Taking the best of those choices for each pair of prefixes gives the matching size for the whole factor.
We then found the least total cost of connected intervals covering the factor. Starting with one interval at the left end, we extended a covered prefix by any overlapping interval ending farther right. Minimizing over these extensions suffices because every connected cover contains such a chain. We grouped factors related by reversal or bit exchange, which preserve their local weights. Among factors whose grouped frequencies differed between P and Q, the smallest cover cost gives the fourth column of Table 1 as a lower bound on the first differing excess. A separate calculation gave the same bound by using vectors of bits to compute matchings and tracking the farthest endpoint reachable at each cost budget.
To show that a difference occurs at the bound, we counted pairs of embeddings directly. At each reduced host site we advance the first pattern index, the second, or both if the next letters agree. We add the integer counts of paths reaching the same pair of indices after the same number of steps. The reduced second moments first differ at the listed excesses. Since earlier coefficients agree and the new coefficient has multiplier one in the restoration formula, that first difference is also the difference in raw moments in the last column. For the three smallest pairs we checked every histogram through the first difference by merging host prefixes that gave identical counts for every pattern prefix still possible to complete.
The guaranteed delay is conservative: at k=401 the formula guarantees equality only at excess zero, whereas the specified pair agrees through excess 22. The upper bound 2k-1 relies on prime length and on just one pattern being a palindrome. How to compute a sufficient host-length cutoff from pattern length alone for arbitrary inequivalent pairs remains open.
References
- Krishna Menon and Anurag Singh. Subsequence frequency in binary words. Discrete Mathematics 347 (2024), 113928. Definition 5.1 and Conjecture 5.2.
- Haobo Ma and Wenlin Zhang. Maximal input entropy for binary two-deletion and two-insertion channels. arXiv:2611.01064 (2026). The ancillary enumeration gives host frequencies by embedding count.
- Bernhard Haeupler, Amirbehshad Shahrasbi and Madhu Sudan. Synchronization strings: List decoding for insertions and deletions. ICALP (2018), 76.
- Roman Kotecký and David Preiss. Cluster expansion for abstract polymer models. Communications in Mathematical Physics 103 (1986), 491–498.