I was trying to figure out a method to get a power of 2 which divides a number x into an odd amount, and got the function $\gcd(x, x - 2^{\lfloor \log_2(x) \rfloor})$, which works well for what I intended. However, after plotting the graph for it in Desmos I got something that resembled a Sierpiński triangle, or at least an approximation of it. What is the reason for this to happen on an unrelated function?
-
1Your formula doesn't work, if I understand what you mean by "the number of times you can divide a whole number by $2$". E.g., for $x = 4$, the answer should be $2$, shouldn't it? But $\gcd(4, 0) = 4$. The resemblance between your function and the Sierpinski triangle doesn't look very close to me. – Rob Arthan Aug 26 '21 at 21:51
-
It actually works slightly differently, it gives you $2^n$ already, instead of the exponent. And if I could post pictures I could show that it actually has it's shape. – Duhon Aug 26 '21 at 21:55
-
Here's another graph to show the shape – Duhon Aug 26 '21 at 22:02
-
1If your formula is intended to deliver something different from what your words imply, then please edit your question. I still find the resemblance with the Sierpinski triangle remote: what point on the graph of your function corresponds to the vertex of the Sierpinski triangle? – Rob Arthan Aug 26 '21 at 22:02
-
I posted the graph with the lines drawing out the shape I see that resembles the Sierpinski triangle, and sorry for the messy question. – Duhon Aug 26 '21 at 22:05
-
I can see now, why you think the graph might look like a sequence of approximations to the Sierpinski triangle. You should fix your question to make the purpose of your formula quite clear. – Rob Arthan Aug 26 '21 at 22:07
-
Do you mean the sequence https://oeis.org/A006519? – peterwhy Aug 26 '21 at 22:11
-
I was aiming to create a function which would output such a sequence actually, but for my purposes what I got, which is a power of 2, worked well, but then I decided to graph the function and got that shape. – Duhon Aug 26 '21 at 22:14
-
1By the way, there are some artifacts in your plot. Try plotting $\gcd(n,2^{1+\lfloor\log_2 n\rfloor})$ to avoid rounding errors when n is a power of two. Also, if you had drawn vertical lines from each point to the x-axis, you might have been asking "why does this look like the markings on an Imperial ruler?" – Kyle Miller Aug 26 '21 at 22:38
1 Answers
The number of times you can evenly divide a whole number $n$ by $2$ is called the "$2$-adic order" or "$2$-adic valuation" (see here and here), and it can be written as $\operatorname{ord}_2n$.
Let's verify the formula you have, that $2^{\operatorname{ord}_2n}=\gcd(n,n-2^{\lfloor \log_2 n\rfloor})$. First of all, there are identities that $\gcd(a,b)=\gcd(a,b-a)$ and $\gcd(a,b)=\gcd(a,-b)$, so in fact your formula reduces to $2^{\operatorname{ord}_2n}=\gcd(n,2^{\lfloor \log_2 n\rfloor})$. There is an odd $m$ such that $n=m2^{\operatorname{ord}_2n}$ by the definition of the $p$-adic order, and a consequence of this is that $$\log_2n = \log_2m+\operatorname{ord}_2n.$$ Since $m\geq 1$ and $\operatorname{ord}_2n$ is a whole number, this shows that $\operatorname{ord}_2n \leq \lfloor\log_2n\rfloor$. Thus, $$\gcd(n,2^{\lfloor\log_2 n\rfloor})=\gcd(m2^{\operatorname{ord}_2n},2^{\lfloor\log_2 n\rfloor})=\gcd(2^{\operatorname{ord}_2n},2^{\lfloor\log_2 n\rfloor})=2^{\operatorname{ord}_2n},$$ where the second equality is from the fact that $m$ is coprime to $2$ and the third is from $\operatorname{ord}_2n \leq \lfloor\log_2n\rfloor$.
What this analysis reveals is that $2^{\lfloor\log_2n\rfloor}$ is some efficient choice of power of two to make everything work. (Theoretically, $2^n$ would work, too.)
Now that we've established that you're definitely graphing $2^{\operatorname{ord}_2 n}$, let's think about its self-similarity. Consider these calculations: \begin{align*} 2^{\operatorname{ord}_2 (2n)} &= 2^{1 + \operatorname{ord}_2 n} = 2\cdot 2^{\operatorname{ord}_2 n}\\ 2^{\operatorname{ord}_2(2n+1)} &= 2^0 = 1 \end{align*} The second is from the observation that $2n+1$ is odd. What this means is we have a rule:
"to plot the values for the range $1,\dots, 2n$, first plot the values for the range $1,\dots,n$, multiply them by two, then insert a $1$ before every value."
For example, here are the first few iterations of this rule: \begin{align*} & 1 \\ & 1,2\\ & 1,2,1,4 \\ & 1,2,1,4,1,2,1,8 \\ & 1,2,1,4,1,2,1,8,1,2,1,4,1,2,1,16 \end{align*}
This is more-or-less the kind of self similarity you would see for a variation on the Sierpinski triangle, where instead of having all three subtriangles being similar to the whole triangle, you only have the bottom two be similar.
- 20,247