14

Question:

For $n \in \mathbb{Z}^+$, define $Z(n)$ to be the number of ones in the binary expression of $n$. For fixed positive integer $a$, how does one describe the set of $b$ such that $Z(ab) = Z(a)Z(b)$?



Bounty Added (Jun 6, 2024):

So far there is one answer provided, and I received a similar answer by email that I paste below; additional ideas and reference pointers are most welcome!

enter image description here

Edit (Jun 4, 2024): In response to two different comments: Corrected an image and introducing Hamming weight, which (in the case of binary strings) refers to the total number of ones in a string. With this additional vocabulary item, the main question can be rephrased as asking when the Hamming weight is multiplicative.

Edit (Jun 3, 2024): I used GPT-4 (link) to create graphs with the following query:

consider a positive integer n. define Z(n) to be the number of ones in the binary representation of n. create a 100 by 100 graph where (a,b) is colored black if Z(ab)=Z(a)*Z(b), and colored white otherwise.

Here is an image of the graph that was produced:

enter image description here

Because of a pattern that looks like the Sierpinski Triangle in the bottom right hand corner of this graph, I followed up by specifically printing graphs where both $a,b$ are in the range $[64, 128]$ and then $[128,256]$. Those images are pasted below:

enter image description here

enter image description here

I suspect this Sierpinski pattern holds for $a,b$ in $[2^k, 2^{k+1}]$ for large $k$, but am not sure how to prove it. Ideas in this direction are welcome, although the intention of this initial question is the bolded question of the top.


Edit asked by author (Jun 8, 2024):

Beautiful $100\times100$ plot (generated by GPT-4o) of the ratio $Z(ab)/(Z(a)Z(b))$ as shades of gray, as dvitek proved that this ratio was in $[0, 1]$.

enter image description here

Nolord
  • 2,233
  • 2
    These links might be of interest. https://oeis.org/A000120 and https://en.wikipedia.org/wiki/Hamming_weight – user4894 Jun 04 '24 at 03:23
  • 1
    Along the lines of the differences formulation, if ${a_i}_i, {b_i}_i$ are positions of ones in the binary expansions of $a,b$, $Z(ab) = Z(a)Z(b)$ when $ {b_i}_i$ is a packing of ${a_i}_i$ in $\mathbb{Z}$. https://doi.org/10.1007/s00605-007-0500-6 might be of interest. – D. Song Jun 06 '24 at 19:45
  • 1
    You could try to plot the graph $Z(ab)/(Z(a)Z(b))$ with shadings of gray ($1$ would mean black) , so we can better see what happens in those white spots. – Nolord Jun 08 '24 at 09:07
  • @D.Song If you are up for posting a more extended answer about this packing approach, then it would be most welcome! – Benjamin Dickman Jun 08 '24 at 15:33
  • 2
    I've added the plot, and I got to say, it is more beautiful than I would have ever expected! – Nolord Jun 08 '24 at 16:18
  • 1
    @Nolord it's fantastic, thank you! It appears that "doubling" coordinates leads to a type of self-similarity; in particular, I expect that if your plot were made for sides of length $[128,256]$ in binary (or $[256,512]$) then it would look increasingly like part of a circle... I'm on the free GPT 4o plan, so I can't create this until late tonight. But you might consider generating it if you have 4o access! – Benjamin Dickman Jun 08 '24 at 16:22
  • 1
    Well, multiplying by $2$ does not change the Hamming weight, so if $Z(a)Z(b)=Z(ab)$ then $Z(2a)Z(b)=Z(2ab)$, so you need to only look at odd $a$'s. – Sil Jun 09 '24 at 19:00
  • @Sil This is a nice observation and, I think, will mean that for fixed $a$, the corresponding set of $b$ (if restricting to those that are odd) will be finite. Or maybe I've overlooked something – TBD! – Benjamin Dickman Jun 09 '24 at 19:08
  • 1
    @BenjaminDickman No it can't be finite. Given an $a$, let $k = \lfloor\log_2 a \rfloor$. Then all the numbers in the set ${1+2^{k+1}, 1+2^{k+2}, 1+ 2^{k+3}, \dots}$ are multiplicative to $a$ in hamming weights – EnEm Jun 10 '24 at 10:34

2 Answers2

12

Here is another definition of $Z(a)$: $Z(a)$ is the minimum number of distinct powers of two needed to write $a$ as a sum of powers of two. (The minimal representation is unique up to the order of the summands.)

Let $a = 2^{a_1} + 2^{a_2} + \cdots + 2^{a_{Z(a)}}$ and $b = 2^{b_1}+2^{b_2} + \cdots + 2^{b_{Z(b)}}$ be two minimal representations. Now $$ab = \sum_{i, j} 2^{a_i+b_j}.$$ So clearly $Z(ab) \le Z(a)Z(b)$, with equality iff none of the $a_i+b_j$ coincide (for then we can combine the colliding summands into a larger power of two). If $a_i + b_j = a_k + b_l$ (for $i \neq k$ and $j \neq l$), then $a_i - a_k = b_j - b_l$. Hence $Z(ab) = Z(a)Z(b)$ precisely when the difference sets of $A = \{a_1, \cdots, a_{Z(a)}\}$ and $B = \{b_1, \cdots, b_{Z(b)}\}$ are disjoint.

This explains several patterns seen in your graphs. For example, if $a = 2^k$, the difference set of $\{k\}$ is empty so there is no restriction on $b$. Similarly, there are more possible $b$s when the binary representation of $a$ is sparse, because then the difference set of $A$ is small (hence easier to avoid). And the Sierpinski-like patterns arise due to numbers having the same difference sets.

dvitek
  • 566
  • +1, thanks! The difference sets formulation is the closest I have seen to a clear description of what I am looking for. At this point, I am not convinced that there is a "nicer" formulation of the set involved. $$ $$ Can you say a bit more about your last sentence? Specifically, what is meant by the Sierpinski-like patterns arise due to numbers having the same difference sets. – Benjamin Dickman Jun 04 '24 at 19:47
  • 3
    There are two easy corollaries of the difference-set formulation: (1) If two numbers $a, a'$ (for example, $a = 20$, $a' = 40$) have the same difference set, then the sets $E(a) = {b: Z(a)Z(b) = Z(ab)}$ and $E(a') = {b: Z(a')Z(b) = Z(a'b)}$ must coincide. So you get a lot of repeats (and almost-repeats) in the vertical columns. (2) If $Z(ab) \neq Z(a)Z(b)$, then the same holds for any $2^{e_1}a+e_2$, $2^{f_1}b+f_2$ whenever $e_2 < 2^{e_1}$ and $f_2 < 2^{f_1}$. So this says that the white regions in your plots have a ton of self-similarity. – dvitek Jun 04 '24 at 23:33
4

I've created a Python code that draws the grayscale plot of the function $Z(ab)/(Z(a)Z(b))$ (see below). Sizes of powers of $2$ generates self-similar fractal that gets more detailed as the power of $2$ gets larger. Perhaps the most beautiful picture is at size $512$ (as they do also get more grayish).

enter image description here

It's interesting to note there are grid-like and quasi-circular patterns. The distorsion in the circular arcs reminds me of the function $|x|^n + |y|^n = 1$.

Feel free to use the code to experiment (or just get nice pictures)!

import numpy as np
import matplotlib.pyplot as plt

def compute_Z_values(size):
    """Compute Z values for all numbers from 1 to size using dynamic programming."""
    Z_values = [0] * (size + 1)
    for i in range(1, size + 1):
        Z_values[i] = Z_values[i >> 1] + (i & 1)
    return Z_values

size = 2**9

# Compute Z(a) for all a in [1, size**2] using dynamic programming
Z = compute_Z_values(size**2)

# Initialize the grid
grid = np.zeros((size, size))

# Fill the grid
for a in range(1, size + 1):
    for b in range(1, size + 1):
        grid[a-1, b-1] = Z[a*b]/(Z[a]*Z[b])

# Create the plot
plt.imshow(grid, cmap='gray', origin='upper')
plt.colorbar(label='Ratio Z(ab) / (Z(a) Z(b))')
plt.title('Gray scale representation of Z(ab) / (Z(a) Z(b))')
plt.xlabel('a')
plt.ylabel('b')
# Save the plot
plt.savefig('Z_plot_' + str(size) + '.png
# Show the plot
plt.show()

Note that changing gray to gray_r in plt.imshow, swaps the blackness and the whiteness.


Edit: Gray scale representation for $a, b \in [2^9, 2^{10}]$:

enter image description here

Nolord
  • 2,233
  • very cool! i ran one more GPT query on $[512,1024]^2$ and dropped the image in at the end of your post in case it ~inspires~ somebody – Benjamin Dickman Jun 09 '24 at 18:47