News for hackers. Stuff that matters.
Re:Powers of 2 in lexical order yield decibels (2019) by kazinator on Monday February 28, 2022 @03:14PM (#30504538)
The lexicographic sort isn't arbitrary:

  1    = 2^0 / 1                                           ~= 2^0
  1.28 = 2^7 / 100   ~= 2^7/(2^6.6439)  ~= 2^(7 - 6.6439)  ~= 2^0.3561
  1.6  = 2^4 / 10    ~= 2^4/(2^3.3219)  ~= 2^(4 - 3.3219)  ~= 2^0.6780
  2.00 = 2^1 / 1                                           ~= 2^1
  2.56 = 2^8 / 100   ~= 2^8/(2^6.6439)  ~= 2^(8 - 6.6439)  ~= 2^1.3561
  3.2  = 2^5 / 10    ~= 2^5/(2^3.3219)  ~= 2^(5 - 3.3219)  ~= 2^1.6780 
  4.0  = 2^2 / 1                                            = 2^2
  6.4  = 2^6 / 10    ~= 2^6/(2^3.3219)  ~= 2^(6 - 3.3219)  ~= 2^2.6780
  8.0  = 2^3 / 1                                            = 2^3

Differences between those powers of two:

  0.3561
  0.3219
  0.3220
  0.3561
  0.3219
These increments are close to 1/3 which is what you need to divide the musical octave (frequency doubling) into 3 steps:

  2^(0/3)  = 1
  2^(1/3) ~= 1.2599
  2^(2/3) ~= 1.5784
  2^(3/3)  = 2
There is a well-known relationship that when you divide a frequency factor of 10 into 10 steps, you get approximately three steps per musical octave (frequency doubling). You can see this on any 31 band graphical equalizer. This relies on the "coincidence" seen the other table shown:

  10^0.0  = 1
  10^0.1 ~= 1.2589
  10^0.2 ~= 1.5849
  10^0.3  = 1.9953
The geometric decade steps provide a close-to-exact doubling also, every three steps.

Right, so where did I get those 6.6439 and 3.3219 numbers? Those are just the approximations of log2(100) and log2(10).

At the heart of the "lexicographic coincidence" seems to be the observation that these logarithms have .64 and .32 fractional parts, or about 2/3 and 1/3.

So for instance since 100 = 2^(log2(100), we can rewrite 1.28 as 128 / 2^(log2(100) which is 2^7/2^(log2(100)).

So then we have powers of two on top and bottom and can subtract them: 2^(7 - log2(100)), which is where we get 7 - 6.6439 = 0.3561.

Re:Powers of 2 in lexical order yield decibels (2019) by gowld on Monday February 28, 2022 @05:10PM (#30505873)
Pulling a bit out, to try to find intuition:

   log_2(10) ~= 10/3

   10^(1/10) ~= cubeRoot(2)
So the first 10 decibels are ~= the first 10 powers of CubeRoot(2)

"dividing by 10^n until you reach 1<y<10" is the operation: CubeRoot(2)^k -> CubeRoot(2) ^ (k mod 10)

So, the scaling operation on 2^m = CubeRoot(2)^3m is going to land on multiples of 1/3, and then sorting will put them in order.

You want 10 values, so you take the first 10 powers of 2. CubeRoot(2)^{0..9}

Remaining question: why do you get 10 distinct values? Well, it's because 2^a and 2^b only scale to the same value if (by logarithms) a - b = 10j.