Prime Patterns with Symmetric Zero Padding: Exploration and Insights
Introduction
Prime numbers often appear randomly distributed at first glance, yet subtle patterns and biases emerge upon closer analysis. As John D. Cook aptly noted, primes “act something like random numbers, except when they don’t” . One way to probe these biases is by imposing structural templates on the integers and measuring how “prime-rich” or “prime-poor” those sets become. In this exploration, we focus on a novel template: numbers constructed with a central midpoint region and symmetrically placed zero-padding on either side, with other digits filling specified open slots. By randomly filling the open slots with digits and checking for primality, we can estimate the prime density – the probability that a number following the template is prime. This approach provides an interactive way to study how primes might “prefer” or “avoid” certain digital patterns, relating to ideas of prime repulsion discussed by mathematicians like Terence Tao (who observed a slight tendency for primes to avoid following too closely behind other primes ).
In the following, we outline the construction of these zero-padded templates, discuss the observed prime densities and trends (including a striking oscillation in prime density when adjusting template parameters), and connect these findings to known results in number theory. We also consider how to formalize and verify properties of these patterns (e.g. using Agda or other formal methods) to ensure the exploration is on solid footing. The goal is to reframe and harden this investigation: transforming ad-hoc code experiments into a rigorous analysis that can reveal new insights about the distribution of primes within constrained numeric sets.
Constructing Templates with Symmetric Zero Padding
At its core, the template approach fixes a certain digit pattern and then examines numbers that conform to that pattern. The pattern is one-dimensional (a linear sequence of digits) and is defined by alternating segments of fixed zeros and variable “open” digits, arranged symmetrically around a midpoint. To construct such a template, one can follow these conceptual steps: • Choose a Midpoint Configuration: Decide on the center of the number. This could be a single digit (if the total length of the number is odd) or a short run of zeros if the total length is even (e.g. using two zeros as the central pair). For example, a template might have a single central digit C as the midpoint, or it might have 00 in the middle as a symmetric center for an even-length number. • Choose Zero-Padding Layers: On each side of the midpoint, insert a run of 0s of a chosen length. The zero-padding is symmetric, meaning if you have (for instance) two zeros immediately to the left of the midpoint, you will also have two zeros immediately to its right. There can be multiple layers of zeros. For example, you might have an inner padding of 1 zero on each side of the center, then later an outer padding of 2 zeros on each extreme end – any such configuration must be symmetric. • Define Open Digit Slots: Between these zero-padding segments, specify positions for open slots where nonzero digits will be placed. These open slots also occur in symmetric pairs (except possibly at the midpoint if the midpoint itself is a single open digit). An “open slot” can be a single digit or even a block of digits that are free to vary. For instance, you might have an open slot at each end of the number (for the first and last digit), and perhaps another open slot on each side just outside the midpoint padding. The values in symmetric open slots are not required to be the same digit – we are not necessarily constructing a palindrome, only a pattern of zeros and variable digits that is symmetric in structure. So, the template enforces which positions are fixed zeros and which are free, but it does not require the free digits on the left to equal those on the right. (If one did enforce identical digits in each symmetric pair of slots, the number becomes a palindrome – a special case of these templates that we discuss shortly.) • Example Template: To make this concrete, consider a template of length 7 digits defined as follows: a single center digit, one zero on each side of the center, and one open digit at each end. In a notation form, it might look like: [X] – 0 – [Y] – C – [Y'] – 0 – [Z], where C is the center digit, 0 are fixed zeros, and [X], [Y], [Y'], [Z] are open slots for digits. The structure is symmetric: the sequence of a fixed zero and an open slot [Y] to the left of center is mirrored by a zero and open slot [Y'] to the right (though the actual digit values in [Y] and [Y'] can differ). The outermost slots [X] (first digit) and [Z] (last digit) form another symmetric pair. This template would generate numbers of the form X0YCY'0Z. If we fill, say, X=3, Y=4, C=5, Y'=7, Z=1, we get the number 304571 (which in this example template has the pattern: 3,0,4,5,7,1 with symmetry in the positions of zeros). We could just as well fill those slots with any other digits, yielding a different number following the same zero structure. • Length and Base Considerations: The “base” here is implicitly 10 (decimal digits), and the length of the number in digits is determined by how many layers of padding and slots we include. The total length will be 2m + (length of midpoint), where m is the sum of all chosen symmetric padding and slot segments on one side of the center. For instance, in the example above, the midpoint length is 1 (the single center digit C), and on one side we have two segments (one zero and one open slot), so total length is 22 + 1 = 5 digits. If we were to “roll over” the midpoint to a longer length (say, let the midpoint be 2 digits instead of 1), the total length increases by 1 (from 5 to 6 in that case). Each time we add an extra zero in each padding segment, the total length increases by 2 (since one zero is added to each side).
Using such templates, we can generate a family of numbers systematically and then investigate how many of those numbers are prime. Essentially, the template acts as a filter on the natural numbers: only those fitting the pattern are considered. We are interested in how dense primes are within that filtered set, compared to the overall density of primes in large numbers.
Prime Density in These Templates
Prime density for a given template is estimated by randomly filling the open slots with digits (according to a uniform distribution over the allowed digits) and checking how often the resulting number is prime. Formally, if a template defines a set
When considering prime density, it’s important to remember the baseline: For large
In our experimentation, we filled the templates uniformly at random with digits and counted primes. We observed that some templates have significantly higher prime density than others. Often this correlates with the template’s ability to dodge small prime divisors. For instance, if a template ensures the last digit is not 0, 2, 4, 5, 6, or 8, then none of the generated numbers will be even or end in 5, automatically eliminating two major classes of composite numbers. This pre-selection would roughly double the prime density compared to completely random numbers (since about half of random numbers are even, and 1/5 are multiples of 5, etc., with overlap) – we essentially built a bit of the sieve of Eratosthenes into the template. On the other hand, if a template inadvertently makes all its numbers divisible by 3 (for example, if the sum of the digits in every number from that pattern is a multiple of 3), then
Key Observation: As we varied the template parameters, we noticed a striking trend: a kind of oscillation in prime density when adjusting the midpoint length and the inner zero padding. In one experiment, a particular template configuration (with a certain midpoint and padding length) yielded a relatively high prime density. However, when we increased the length of the midpoint by one digit (essentially moving to the next “size” of numbers, an order of magnitude larger), the prime density dropped sharply. Then, by extending the innermost zero-padding (adding an extra 0 on each side of the midpoint in the pattern), the prime density rose again, nearly restoring the original level. In other words, as we grew the length of the number (especially increasing the midpoint), primes seemed to “run away” (becoming rarer), but adding more internal zeros pulled them back (making primes more common relative to the new size). This gave the impression of a wave-like pattern – metaphorically, a “sine wave” moving across a 2D graph, where one axis is the midpoint length and another could be the amount of padding, with peaks (high density) and troughs (low density) alternating.
To understand this phenomenon, consider what happens when we change these parameters: • Increasing Midpoint Length: Adding a digit to the midpoint usually increases the overall length of the number by 1 (if going from an odd-length number to an even-length, or vice versa). This has two effects. First, the numbers in the template become roughly 10 times larger, so primes are inherently less frequent by a log-factor. But secondly, changing the parity (odd/even) of the total length of the number can introduce or remove certain divisibility biases. Notably, if a symmetric template goes from an odd total length to an even total length, it might introduce a divisibility-by-11 condition (more on this below). This can drastically reduce prime density because a whole new swath of the template’s numbers become composite due to that factor. In our experiments, when the midpoint length increased such that the total number of digits became even, the prime density plummeted – many numbers in the template were now divisible by 11 or other small primes. • Increasing Inner Zero Padding: Adding an extra zero on each side of the midpoint keeps the total length parity the same (since we add two digits total). What this often does is separate the other free digit slots further from the center. This can alter the arithmetic properties of the numbers in the template. For example, adding zeros can change the residue of all template numbers modulo small primes. In the case where the midpoint change had caused a divisibility-by-11 issue, adding two zeros on each side effectively made the total length odd again (if it was even) or at least disrupted the symmetry that was causing the problem. We observed that prime density climbed back up after this padding increase, indicating that the template was no longer trapping numbers into a bad congruence (like multiples of 11), and the primes “returned.”
To illustrate the dramatic impact of such structural constraints, consider the special case of palindromic numbers (which are a subset of our templates where all digits mirror symmetrically, not just the zeros). It is a known fact that any base-10 palindrome with an even number of digits is divisible by 11 . For example, 1221 is divisible by 11, as is 9889, etc. The only even-length palindrome that is prime is 11 itself – beyond that, if you have an even number of digits and the number reads the same forwards and backwards, it will have 11 as a factor by a simple application of the divisibility rule for 11. This means a template that produces even-length palindromes will have zero prime density (besides the trivial case 11). On the other hand, palindromes with an odd number of digits can sometimes be prime (e.g. 101, 131, 757 are odd-length palindromic primes). However, even among those, primes get rarer as the length increases. In fact, it has been proven that “almost all palindromes are composite,” meaning that the proportion of palindromic numbers that are prime tends to 0 as we go to large numbers . This is partly due to the accumulation of many small-factor constraints (for instance, half of all palindromes with odd length will be divisible by 3 because the sum of their digits is often a multiple of 3, etc., and more subtle reasons ).
Figure: Palindromic primes by digit-length (plotted on a logarithmic scale). This chart shows the number of base-10 palindromic primes that have a given number of digits (data compiled from known results and OEIS). Notice that no primes exist with an even number of digits (bars for 2, 4, 6, 8 digits are zero) since any even-length palindrome is divisible by 11 . The counts for odd-digit palindromic primes do grow as digit-length increases (e.g. there are more 7-digit palindromic primes than 5-digit ones, and many more 9-digit palindromic primes than 7-digit), but the density of primes among palindromes drops. In fact, the ratio of palindromic primes to all palindromic numbers diminishes towards zero for large
Our symmetric-zero templates are more general than palindromes, but the palindromic case vividly demonstrates prime-repelling constraints: when the template’s symmetry is too strict (full digit-wise mirroring), it injects a strong bias like divisibility by 11 that “repels” primes (no large primes can survive it). In our exploration, we allowed the left and right slots to differ in value, which avoids the extreme of every even-length number being composite by 11. However, even without full mirroring of digits, certain patterns still suffer from lesser but significant biases. For example, in a 6-digit template X000Y (with no center digit, basically the pattern
What we saw in the “sine wave” oscillation was essentially the interplay of these effects as the parameters changed. When the midpoint extension caused the total length parity to flip, it introduced something like an “11-divisor wall” (prime density cratered). When we then extended the innermost zeros, that parity flipped back or the alignment with 11 was disrupted, removing the wall (prime density rose again). In addition, making the number longer without adding zeros meant more of those numbers fell prey to small factors like 3, 7, 9, etc., simply because there were more digits contributing to such conditions. Adding zeros, in a sense, diluted some of those conditions (zeros don’t contribute to digit sums, for instance, so the more zeros, the less often a random fill will sum to a multiple of 3). Thus, a template with more zero padding can paradoxically have a higher prime density than a similar-length template with less zeros, because the zeros act as placeholders that reduce the “randomness” (and thus reduce the chance of hitting certain composite-forming patterns). Primes seem to prefer some breathing room in the form of zeros!
In summary, the experiments demonstrated that prime distribution is not uniform across digital patterns. Some patterns are prime-rich, avoiding many small factors (hence showing higher prime density than average), while others are prime-poor because they force inclusion of small factors. This is directly connected to what Tao refers to as the primes’ “slight but non-trivial repulsion” – primes aren’t truly random; they have negative auto-correlations caused by small divisors . If one number is prime, the number that is, say, 2 away is less likely to be prime than a random number would be, because one of them is even; if one number is prime, a number 6 away might be slightly less likely because one of them might hit a 3-multiple, etc. In our context, if one template configuration is conducive to primes, a slight alteration that aligns the numbers with a new modulus can make primes repel that configuration until another adjustment is made. The oscillating density was essentially the primes dodging the traps of each successive configuration until we realigned the template favorably again.
Preferential Patterns and Theoretical Context
The notion that primes have preferences or avoidances for certain patterns can be framed in terms of modular arithmetic and classical number theory results. A template as we described can be thought of as defining a set of congruence conditions (mod some power of 10). For example, consider the simple template X000Y (with
However, our templates often correspond to unions of many progressions (because multiple slots mean multiple degrees of freedom rather than one unique progression). This makes the exact counting complicated, but heuristically one can extend Dirichlet’s intuition: if there is no fixed prime divisor forced by the template, we expect infinitely many primes to appear in the template (this is a consequence of the broader Schinzel’s Hypothesis H, which generalizes Dirichlet’s theorem to multiple linear forms). Conversely, if the template imposes a fixed factor (like every number in it is even, or every number in it is divisible by 11), then obviously primes (beyond maybe one special case) cannot occur.
The palindromic numbers scenario is a cautionary tale. It satisfies the condition of “no fixed prime divisor” only in the odd-digit case (since even-digit palindromes have 11 as a fixed divisor). It is widely believed that there are infinitely many palindromic primes in base 10, but this remains unproven. Heuristic models suggest that the count of palindromic primes below
That said, within finite ranges, these patterns can have significantly higher prime hit-rates than random numbers of comparable size. For example, when we restricted to the template X000Y and further required that
The bottom line is that primes are distributed across these congruence-defined sets, but not evenly – there are biases. For large random numbers, primes are equidistributed across allowable residues mod any fixed
From a theoretical standpoint, one could attempt to calculate the expected prime density for a given template by multiplying the conditional probabilities of surviving each relevant small prime constraint. For example, if a template ensures the number is never even and never ends in 5, that multiplies the chance of primality by roughly
In summary, primes do exhibit preferential presence in sequences that cleverly avoid small factors. Our symmetric-zero templates gave us a playground to see this: by tuning the template, we were effectively toggling certain divisibility conditions on and off, and the primes responded in turn (surging in density when conditions were favorable, and disappearing when conditions were hostile). This is a concrete demonstration of primes’ “subrandom” nature – not random, but subtly structured .
Formalizing and Extending the Exploration
To solidify these observations, it would be valuable to formalize the problem in a proof assistant or at least in precise mathematical language. Using a system like Agda (a dependently typed programming and proof language) or other theorem provers, we can define the templates and prove certain basic properties about them. This would ensure our code (which has been exploratory and sometimes messy) aligns with mathematical truth and doesn’t overlook edge cases. Here are a few directions for formalization and further development:
• Defining the Template Predicate: We can define a predicate or type IsPattern(n, pattern) that is true if and only if the integer n matches a given template specification. For example, IsPattern(n, [d1, k0, d2]) might mean “n is a number whose first digit is d1, followed by k zeros, and last digit is d2.” More complex patterns (multiple open slots and layers of zeros) can be built up inductively. In Agda, one could use a record or data type to represent a template (with fields for midpoint, zero lengths, etc.) and a function that given an integer and a template returns either a proof that the integer fits the template or a refutation.
• Proving Deterministic Properties: With the formal template definition, we can prove theorems like “If a number fits an even-digit palindrome template and is greater than 11, then 11 divides that number.” Formally, for a template that mirrors all digits and has even length, we show IsPattern(n, evenPalindrome) -> 11 ∣ n (for n > 11). This follows from a simple inductive proof or direct argument about the alternating sum of digits , and indeed a proof by induction is referenced in the literature (as noted by P. De Geest and others). Having this theorem in Agda would guarantee that any time our program tries to count primes in an even-length palindrome pattern beyond 11, we know the answer should be zero – a useful sanity check.
• Avoiding Trivial Composites: We might also formally prove that certain templates inherently avoid some small primes. For instance, if the template does not allow the last digit to be even, then we can prove IsPattern(n, template) -> n mod 2 ≠ 0. This is trivial to us, but encoding it ensures no oversight. Likewise for last digit not 5, we get n mod 5 ≠ 0. These can be combined: if both hold, then gcd(n, 10) = 1 for all n in the pattern, which is a precondition for Dirichlet’s theorem to guarantee some primes. In Agda, such properties become lemmas that can be reused in reasoning about prime existence.
• Connecting to Infinitude of Primes in Patterns: While a full proof that a given pattern has infinitely many primes is beyond current reach in most cases (it would solve open problems if we could prove it for palindromes, for example!), we can sometimes reduce the problem. For instance, some templates reduce to a single linear form. If our template results in numbers that always equal, say, a mod m for some m (and vary freely otherwise), then we are in the territory of Dirichlet’s theorem. We could attempt to use known results or even import a proof of Dirichlet’s theorem to assert infinite primes in that progression. For more complex templates that yield a union of progressions, one might at least argue heuristically or attempt a computational verification for large ranges as evidence.
• Computational Verification and Visualization: On the software side, we would refactor the code to be cleaner and more interactive. We can introduce parameters for midpoint length, padding lengths, etc., and automatically compute prime densities for each combination. This could generate a surface or heat map of prime density over the parameter space. The “sine wave” we described could be visualized as a ridge of high density moving diagonally when plotted against midpoint length and zero padding. By hardening the code, we also ensure it properly handles edge cases (like leading zeros in a pattern which would actually make the number shorter than intended, or excluding the case where the only prime is 2 or 5, etc.). We would incorporate fast primality tests (perhaps Miller-Rabin or a deterministic test for the sizes we explore) and possibly a sieving step to avoid testing obviously divisible cases (though our pattern inherently does some sieving).
• Collaboration between Computational and Formal Methods: Agda (or another proof assistant) could in fact be used to verify some of the computation results for small cases. For example, we could formally prove the list of all 3-digit palindromic primes is {101, 131, 151, 181, 191, 313, 353, 373, 383, 727, 757, 787, 797, 919, 929} – this is tedious but doable. A more fruitful angle is to use computation to guide conjectures (e.g. “pattern P has higher density than pattern Q for large ranges”) and then use theory to explain why. Our collaboration moving forward can involve identifying which patterns are worth deeper theoretical study (perhaps those that maximize prime density for a given length) and then trying to characterize those patterns’ properties.
• Applying Tao’s Random Model Heuristics: Tao’s work on probabilistic models for primes  could be insightful to formally apply. We could treat the template’s residues as conditions in a modified Cramér random model: normally, we assume each number
In conclusion, formalizing the problem would not only verify specific claims (like the 11-divisibility of even palindromes) but also provide a language to ask deeper questions: Is there an optimal pattern that maximizes prime density for a given length? Could we prove any non-trivial lower bounds for prime counts in a template (conditional results using assumed hypotheses)? These are challenging tasks, but with a combination of improved code, theoretical insight, and possibly interactive visualization, we can make progress. The intellectual excitement here lies in marrying computational experimentation with rigorous number theory – every pattern that shows an interesting behavior prompts us to explain it with a theorem or heuristic. By reframing the exploration in this comprehensive way, we ensure that each new observation (e.g. a drop or jump in the prime counts) is accounted for by some known principle (like a new small prime divisor coming into play or being averted).
This collaboration opens several avenues: cleaning and structuring the existing code (bringing it to a robust “2.0” state), systematically exploring the parameter space for prime-rich patterns, proving fundamental lemmas about those patterns, and perhaps even discovering new prime constellations or conjectures (for example, one might conjecture that for any fixed pattern that doesn’t enforce a modulo-2 or modulo-5 or modulo-3 trap, there are infinitely many primes – a generalization of Dirichlet’s theorem in spirit). While some of these are big conjectures in disguise, testing them on our symmetric zero templates provides evidence and insight.
It’s indeed intellectually activating to see prime numbers “dance” to the tune of our templates – avoiding some rhythms and resonating with others. By hardening our approach with formal verification and thorough analysis, we can turn this exploratory music into a well-scored theory, ensuring that every note (or zero) is accounted for in the grand symphony of prime numbers.
References
• Tao, Terence. Probabilistic models and heuristics for the primes. (Supplement to 254A lectures) – discusses slight deviations from randomness in prime distribution  .
• Wikipedia: Palindromic prime – notes that any even-digit palindromic number greater than 11 is composite (divisible by 11), and that asymptotically almost no palindromes are prime .
• P. De Geest’s World of Numbers – provides data and proofs on palindromic primes, including the proof of the even-digit palindrome rule  and references to Banks et al. (2004) on the density of palindromes .
• John D. Cook’s blog – Leading digits of primes (2023) – highlights bias in prime leading digits and the “random except when not” nature of primes .
• MathOverflow discussion (2011) – “Why so difficult to prove infinitely many restricted primes?” – contains heuristic argument for palindromic primes count