Digit Substitution Sequences

About three years ago, I played with a string substitution system based on the NATO phonetic alphabet. That system generated fractal sequences of words, but it did not easily lend itself to numbers.  So, recently I set out to find a similar system that worked with numbers.  The characteristics of the NATO system that I wanted this new thing to have were:
  • It would be an iterative digit substitution scheme.  At each step, the digits in the previous iteration’s sequence would be substituted with others to create the next step’s sequence.
  • The substitution rules would generally be the same for each digit, but might lead to different specific results, based on the value of the digit.
  • The system would lead to a fractal sequence of digits.
As you might imagine, there are many ways to do this, depending on how the new numbers are generated from the old.  In order for this to work in a fashion similar to the NATO system, the new number needs to be a non-negative integer, just like the source numbers (the numbers 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9).  For added interest, the new numbers should not all have the same number of digits, just like the words in the NATO phonetic alphabet do not all have the same number of letters.  One simple approach is to just square the original number, giving the substitutions shown in the table below.

Original
Substitution
0
0
1
1
2
4
3
9
4
16
5
25
6
36
7
49
8
64
9
81

Using this rule, nothing interesting happens beginning with 0 or 1.  The substitution is the same as the original numeral, so the sequence of numerals is 0, 0, 0, … or 1, 1, 1, …  Using 2 as a starting point yields some variation.  Here are the first several steps:
  1. 4 (2 is replaced with 4)
  2. 16 (4 is replaced with16)
  3. 136 (the 1 is replaced with 1 and the 6 is replaced with 36)
  4. 1936
  5. 181936
  6. 164181936
  7. 13616164181936
  8. 193613613616164181936
  9. 1819361936193613613616164181936
  10. 1641819361819361819361936193613613616164181936
There are some interesting patterns in this sequence.  From the second iteration on, the first digit is always 1, since 1 is replaced with 1 at each step.  Looking further, the first digits repeat every fourth iteration, in the pattern 16…, 13…, 19…, and 18…  Comparing the sixth and tenth iterations (for example), the entire sequence at the earlier step is repeated as the beginning of the later step (which is about five times as long).

Even though this series of sequences began with 2, 2 never shows up after that.  The only numerals that appear after the first few steps are:  1 (about one-third of the time), 3 (17%), 4 (5%), 6 (26%), 8 (8%), and 9 (11%).

On the back end, the same pattern of ending digits repeats and builds.  Aligning the 10 steps on the right shows this more clearly.  From the fifth step on, the entire previous sequence forms the end of the next sequence.

16
136
1936
181936
164181936
13616164181936
193613613616164181936
1819361936193613613616164181936
1641819361819361819361936193613613616164181936
136161641819361641819361641819361819361819361936193613613616164181936

This “back-end” sequence, except for the initial 1, can be constructed by using the same substitution scheme and beginning with 6 instead of 2 (6 becomes 36, which becomes 936, then 81936, etc.).  That 2 and 6 wind up with essentially the same patterns suggests what happens with other starting numerals.  Looking at the squares in the table above, 3 goes to 9, so 3 and 9 will lead to the same patterns.  The first numeral of 81 (9 × 9) is 8, so 9 and 8 will end up the same way.  And the first numeral of 64 (8 × 8) is 6, so 3, 6, 8, and 9 will all have the same destiny.  They will lead to sequences that begin with the same four sets of numerals, each repeating every fourth iteration:

•    36161641819361641819361641819361819361819361936193
•    64181936181936181936193619361361361616418193618193
•    81936193619361361361616418193619361361361616418193
•    93613613616164181936136161641819361361616418193616

Likewise, 2 × 2 is 4, so 2 and 4 will share the same path.  The first numerals of 25 (5 × 5) and 49 (7 × 7) are 2 and 4, so the starting points of 2, 4, 5, and 7 will all lead to the same results.  These patterns are the same as those for 3, 6, 8, and 9, except that these begin with 1.  The leading 1 has no impact on the rest of the sequences, but is simply carried on from one step to the next.

Other functions, aside from squaring, can be used and give different results.  For example, each numeral can be replaced with the cube of its number:

Original
Substitution
0
0
1
1
2
8
3
27
4
64
5
125
6
216
7
343
8
512
9
729

Here, as with squaring, beginning with 0 or 1 just leads to the same number again.  Since 23 = 8, beginning with 2 or 8 results in the same pattern:
•    2
•    8
•    512
•    12518
•    181251512
•    151218125112518, etc.

The last digits build a pattern that repeats every second iteration, ending with 518 or 512.  Continuing a few more steps, the patterns grow to:
•    …51218125111812515121125181512181251151218125112518 and
•    …18125151211251815121812511125181512181251181251512

Inserting spaces between digits or groups of digits, you can see how, working from right to left,  concatenating the cubes of the digits in one sequence gives exactly the digits in the other, and vice versa.  In a sense each sequence creates the other.

•    …51218125111812515121125181512181 2 5 1 1 5 1 2 1 8 1 2 5 1 1 2 5 1 8
•    …18125151211251815121 8 125 1 1 125 1 8 1 512 1 8 125 1 1 8 125 1 512

•    …51218125111812515121 125 1 8 1 512 1 8 125 1 1 512 1 8 125 1 125 1 8
•    …18125151211251815121812511125181 5 1 2 1 8 1 2 5 1 1 8 1 2 5 1 5 1 2

The same thing happens with starting points of 3 and 7, but leading to two different sequences:

•    …83432166483435121812168121621664125188343216648343
•    …21681216216641812515125122764278121621664512276427

•    …83432166483435121812168121621664 1 2 5 1 8 8 3 4 3 2 1 6 6 4 8 3 4 3
•    …2168121621664 1 8 125 1 512 512 27 64 27 8 1 216 216 64 512 27 64 27

•    …8343216648343512 1 8 1 216 8 1 216 216 64 125 1 8 8 343 216 64 8 343
•    …21681216216641812515125122764278 1 2 1 6 2 1 6 6 4 5 1 2 2 7 6 4 2 7

The other four numbers, 4, 5, 6, and 9, give rise to their own sequences.  In these cases, each sequence generates itself.  Working right to left, replace each digit with its cube and you’ll recover the same sequence.  Alternatively, each group of digits that forms a perfect cube can be replaced by its cube root to get back to the same sequence.  For example, in 4’s sequence, starting from the right and replacing the last two digits (64) with 4 and each of the previous 216 with 6, gives 664, the last three digits of the sequence.

•    4:  …11251815121812161251815121812165121812168121621664
•    5:  …18125151211512181251125181181251512112518151218125
•    6:  …81251512115121812511251811812515121125181512181216
•    9:  …22764271812515128343216648343125182764275123438729

To generate images from all of these numbers, I used the same basic process described in the NATO post—drawing a series of line segments at different angles.  Take two sequences (not necessarily different).  March through the sequences one digit at a time.  The digit from the first sequence represents the angle to turn before drawing the segment and the digit from the second is the length of the segment.  In the image at the top of this post, I used the squaring sequence starting with 5 to determine the lengths and the cubing sequence starting with 5 to determine the angles.  The cube digits were multiplied by 90° to make sure that all the angles were right angles.  For something completely different, this image used adding for both sequences.  Starting with 9, add 17 to each digit for the length.  For the angles, start with 7 and replace each digit with 19 times its value.  Then, multiply those digits by approximately 179.632149°.