Wednesday, June 12, 2024

[vkhdrcsg] encoding number size with digit grouping

grouping chunks of digits with commas the standard way makes it easier to tell how large a number is:

1 digit number: 1
2 digits: 22
3 digits: 333
4 digits: 1,333
5 digits: 22,333
6 digits: 333,333
7 digits: 1,333,333
8 digits: 22,333,333
9 digits: 333,333,333
10 digits: 1,333,333,333
11 digits: 22,333,333,333

however, when numbers get even larger, it becomes hard to count the number of groups of 3.  we propose a non-uniform grouping of digits to make counting slightly easier.

the general idea is as follows:

1 + 1 + 1 + 1 + 3 + 3 = 10
10 + 10 + 10 + 10 + 30 + 30 = 100
(1 + 1 + 1 + 1 + 3 + 3) + 10 + 10 + 10 + 30 + 30 = 100

in the third line above, we have substituted the first line into the first "10" in the second line.  this can be continued recursively for larger powers of 10.  (previously, powers of 2.)  groupings of 1, 3, 10, 30, 100, 300, and so forth allow identifying chunks of a power of 10 digits.

here are sample numbers of 1 through 10 digits with inserted commas.  (special cases: optionally omitting commas for numbers of 1 through 4 digits.)

1 digit: 1
2 digits: 1,1 (or 11)
3 digits: 1,1,1 (or 111)
4 digits: 1,1,1,1 (or 1111)
5 digits: 1,1,333
6 digits: 1,1,1,333
7 digits: 1,1,1,1,333
8 digits: 1,1,333,333
9 digits: 1,1,1,333,333
10 digits: 1,1,1,1,333,333

if a number grows or shrinks by one digit, the comma pattern can radically change, as it does between 4 and 5 digits, and between 7 and 8.  this might be confusing compared to the standard system of groups of 3.  but radical change in appearance when a number has changed by a factor of 10 might be beneficial.

(the Indian numbering system (lakh, crore, etc.) has non-uniform digit groupings, though not as extreme as this.)

to handle a number of 10*a + b (a<10) digits, first add commas to the first 10*a digits by itself, then recursively the next b digits, then concatenate.  in other words, treat the length one digit at a time.  in the examples below (and above), for ease of understanding, we also give the number of digits in each digit grouping as the digits of that grouping.

11 digits: 1,1,1,1,333,333,1
12 digits: 1,1,1,1,333,333,1,1
13 digits: 1,1,1,1,333,333,1,1,1
14 digits: 1,1,1,1,333,333,1,1,1,1
15 digits: 1,1,1,1,333,333,1,1,333
16 digits: 1,1,1,1,333,333,1,1,1,333
17 digits: 1,1,1,1,333,333,1,1,1,1,333
18 digits: 1,1,1,1,333,333,1,1,333,333
19 digits: 1,1,1,1,333,333,1,1,1,333,333
20 digits: 1,1,1,1,333,333,1010101010
21 digits: 1,1,1,1,333,333,1010101010,1
22 digits: 1,1,1,1,333,333,1010101010,1,1
23 digits: 1,1,1,1,333,333,1010101010,1,1,1
24 digits: 1,1,1,1,333,333,1010101010,1,1,1,1
25 digits: 1,1,1,1,333,333,1010101010,1,1,333
26 digits: 1,1,1,1,333,333,1010101010,1,1,1,333
27 digits: 1,1,1,1,333,333,1010101010,1,1,1,1,333
28 digits: 1,1,1,1,333,333,1010101010,1,1,333,333
29 digits: 1,1,1,1,333,333,1010101010,1,1,1,333,333
30 digits: 1,1,1,1,333,333,1010101010,1010101010
31 digits: 1,1,1,1,333,333,1010101010,1010101010,1

the length of a number can therefore be read off one digit at a time.  if a digit group size increases, it  increases only by 3 or 10/3 .  the next digit of the length begins when the grouping size decreases to one: ",X,".  this resembles the "ladders" in a previous post about digit sequences.  (originally those digit sequences were developed to serve as sample digit groups for this post, but 333 and 1010101010 etc. ended up being simpler.)

(counterpoint: for just communicating the size of a number, much simpler than the madness proposed here is scientific notation: 120000 = 1.2e5)

below are the sizes of digit groups for numbers whose number of digits is of the form d*10^n .

1 digit: 1
2 digits: 1 1
3 digits: 1 1 1
4 digits: 1 1 1 1
5 digits: 1 1 3
6 digits: 1 1 1 3
7 digits: 1 1 1 1 3
8 digits: 1 1 3 3
9 digits: 1 1 1 3 3
10 digits: 1 1 1 1 3 3
20 digits: 1 1 1 1 3 3 10
30 digits: 1 1 1 1 3 3 10 10
40 digits: 1 1 1 1 3 3 10 10 10
50 digits: 1 1 1 1 3 3 10 30
60 digits: 1 1 1 1 3 3 10 10 30
70 digits: 1 1 1 1 3 3 10 10 10 30
80 digits: 1 1 1 1 3 3 10 30 30
90 digits: 1 1 1 1 3 3 10 10 30 30
100 digits: 1 1 1 1 3 3 10 10 10 30 30
200 digits: 1 1 1 1 3 3 10 10 10 30 30 100
300 digits: 1 1 1 1 3 3 10 10 10 30 30 100 100
400 digits: 1 1 1 1 3 3 10 10 10 30 30 100 100 100
500 digits: 1 1 1 1 3 3 10 10 10 30 30 100 300
600 digits: 1 1 1 1 3 3 10 10 10 30 30 100 100 300
700 digits: 1 1 1 1 3 3 10 10 10 30 30 100 100 100 300
800 digits: 1 1 1 1 3 3 10 10 10 30 30 100 300 300
900 digits: 1 1 1 1 3 3 10 10 10 30 30 100 100 300 300
1000 digits: 1 1 1 1 3 3 10 10 10 30 30 100 100 100 300 300
2000 digits: 1 1 1 1 3 3 10 10 10 30 30 100 100 100 300 300 1000
3000 digits: 1 1 1 1 3 3 10 10 10 30 30 100 100 100 300 300 1000 1000
4000 digits: 1 1 1 1 3 3 10 10 10 30 30 100 100 100 300 300 1000 1000 1000
5000 digits: 1 1 1 1 3 3 10 10 10 30 30 100 100 100 300 300 1000 3000
6000 digits: 1 1 1 1 3 3 10 10 10 30 30 100 100 100 300 300 1000 1000 3000
7000 digits: 1 1 1 1 3 3 10 10 10 30 30 100 100 100 300 300 1000 1000 1000 3000
8000 digits: 1 1 1 1 3 3 10 10 10 30 30 100 100 100 300 300 1000 3000 3000
9000 digits: 1 1 1 1 3 3 10 10 10 30 30 100 100 100 300 300 1000 1000 3000 3000

for example, the digit grouping of a 555-digit number is first the digit grouping of a 500-digit number, 1 1 1 1 3 3 10 10 10 30 30 100 300 , then the digit grouping of a 50-digit number 1 1 1 1 3 3 10 30 , then the digit grouping of a 5 digit number, 1 1 3 , so the entire digit grouping is 1 1 1 1 3 3 10 10 10 30 30 100 300 1 1 1 1 3 3 10 30 1 1 3 .  here is an example 555-digit number with commas so inserted:

1,1,1,1,333,333,1010101010,1010101010,1010101010,303030303030303030303030303030,303030303030303030303030303030,1001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001,300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300300,1,1,1,1,333,333,1010101010,303030303030303030303030303030,1,1,333

here is a sample 105-digit number, illustrating that nothing special happens when the length has an internal zero.  the digit grouping is 1 1 1 1 3 3 10 10 10 30 30 1 1 3:

1,1,1,1,333,333,1010101010,1010101010,1010101010,303030303030303030303030303030,303030303030303030303030303030,1,1,333

because internal digit chunks can get arbitrarily long, this method of grouping is not helpful for providing visual breaks for a human reading or transcribing the digits.  it is not too helpful for locating a particular digit by index.  previously, varied separator characters to solve these problems.

source code in Haskell to generate digit group sizes and perform groupings.

No comments :