A shower thought turned into a Collatz visualization

原始链接: https://abstractnonsense.com/collatz/

著名的未解数学难题——考拉兹猜想,激发了一种独特的可视化方法。其核心思想是追踪对正整数反复应用考拉兹函数时产生的“偶数/奇数”分支序列。将这些分支视为二进制数字,可以为每个整数创建一个分数。为了减轻潜在的偏差,使用了“快捷”考拉兹函数,在“3n+1”步骤之后立即除以2。 绘制这些所得分数显示出看似均匀的分布。然而,将连续的分数对作为二维空间中的坐标绘制出来,却产生了惊人的自相似图案。尽管这种方法最初很新颖,但奥利维尔·罗齐耶(2019年)和桥本幸弘(2007年)已经使用2-adic数而不是直接的分数映射探索过这种方法。尽管构建方式不同,但所得图像相同。这种可视化方法虽然并非考拉兹猜想的解,但却提供了对其行为的迷人一瞥,并有可能激发进一步的研究。

Hacker News 最新 | 过去 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 一个洗澡时想到的点子变成了漂亮的考拉兹猜想可视化(abstractnonsense.com) 32 分,来自 abstractbill,53 分钟前 | 隐藏 | 过去 | 收藏 | 1 评论 manwe150 6 分钟前 [–] 关于随机性,我一直想知道考拉兹序列是否与具有乘数 3/2、无限长度状态向量和输出模 2 的常用伪随机数生成器的属性有关,公式如下:https://en.m.wikipedia.org/wiki/Linear_congruential_generato.... 我认为这可能是使该猜想既有趣又困难又美丽的因素之一。很酷的是,可以看到随机性中也隐藏着一些模式! 回复 指导原则 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系我们 搜索:

原文

I recently went on a nice long SCUBA diving trip with my wife and daughters. Lots of diving implies lots of showers, and lots of showers means lots of shower-thoughts! An especially interesting one I had turned into a nice way to visualize some aspects of the Collatz Conjecture.

The Collatz Conjecture defines a very simple function on all positive integers as follows:

  • If the number is even, divide it by 2
  • If the number is odd, multiply it by 3 and then add 1

If you can prove that repeated applications of this function, starting from any positive integer, will eventually reach 1 then you have proved the Collatz Conjecture and won a million dollars and plenty of fame and glory!

Individual inputs are trivial to verify. For example, if we start with 6, we get:

  • 6 is even, so 6 / 2 → 3
  • 3 is odd, so 3 × 3 + 1 → 10
  • 10 is even, so 10 / 2 → 5
  • 5 is odd, so 5 × 3 + 1 → 16
  • 16 is even, so 16 / 2 → 8
  • 8 is even, so 8 / 2 → 4
  • 4 is even, so 4 / 2 → 2
  • 2 is even, so 2 / 2 → 1

But the real work is proving that this happens for all positive integers. So far, no one has been able to do that.

I'm not going to solve the Collatz Conjecture. Somehow I'm turning 50 this year, and my PhD was more than two decades ago (and in a branch of math that's unlikely to impact the conjecture). But I love that it's just there, waiting and inspiring people. I hope to see it solved in my lifetime.

Anyway, my shower-thought was that it would be nice to visualize this repeated application of the Collatz function for many positive integers all at once, rather than just one at a time. To do that, I thought, why not keep track of the sequence of branches taken for each input and then since there are only two branches, why not treat them as binary digits?! We could use those binary digit sequences to make a fraction from each input, by summing 2-nbn for each bit bn in the sequence, making it really easy to graph them and perhaps more easily see what the Collatz process is doing.

After a little more thinking I decided this approach would be a little too naive. The output of the Collatz function at each step seems like it would be biased towards producing even numbers, making the bit-sequences more full of one binary digit than the other, and maybe obscuring any interesting features we could otherwise see. I decided I would fix that by immediately dividing by 2 at the end of the 3n + 1 step (since we know 3n + 1 will be even if n is odd). It turns out this idea is well-known, as the "shortcut" Collatz function.

With that tweak, here's a simple JavaScript implementation of this idea:

function collatzBits(n) { 
    let bits = [];
    while (n !== 1) {
        if (n % 2 === 0) {
            bits.push(1);
            n = n / 2;
        } else {
            bits.push(0);
            n = (3 * n + 1) / 2;
        }
    }
    return bits;
}

function bitsToFraction(bits) { 
    let fraction = 0;
    for (let i = 0; i return fraction;
}

Here's an interactive version you can play with. Try putting in a few numbers to see how the Collatz process gets encoded into binary fractions.

Choose an input n =
The corresponding sequence of bits, interpreted as a binary fraction, is 0.02
which is 0 as a decimal.

Something fun to think about: How long of a bit-sequence can you construct? Can you make an arbitrarily long one, by choosing the right starting number?

Of course, now that we have a mapping from positive integers to fractions, we can also plot them.

Here's a plot of the Collatz fractions for the first N positive integers. You can adjust N to see more points. Try some big values of N to get a sense of the distribution of the Collatz fractions. N =

The points look quite uniformly distributed to me. If I squint, then maybe I can see some structure, but it's hard to describe and I could be imagining it.

After making this plot I remembered a nice trick I read about as a teenager in James Gleick's fantastic book "Chaos" (I think the idea might have been attributed to Feigenbaum). The trick is that, when you have a sequence of numbers that seem random, you should try treating subsequent pairs of numbers as coordinates in a 2D plot. For our sequence of "Collatz fractions", fn, we would plot the points (fn, fn+1) for n = 1, 2, 3, ... N.

I did that, and was so surprised by the result I first thought I must have made a mistake in my code. But I hadn't, the patterns are real. They look almost like some kind of alien "writing" to me, and there's so much beautiful self-similarity in them. To dig deeper into the structure, I added a way to color points that match simple javascript rules. Here's an interactive version of that, with a few of my colorizing rules. You can add more of your own too!

Here's the plot for the first N integers, where N = If you zoom far enough to see gaps between points, increase N (but the plot will be slower!)

I find this incredibly fun to play with, zooming deep in and adding new color rules and seeing how they change the plot. Depending on what device you're viewing this on, you should be able to pinch or scroll to zoom in and out, and drag it around to see different parts of it.

I had already done a quick literature search to see if anyone else had done something similar, but hadn't found anything so far. I wrote down some ideas I thought might possibly turn into a proof of the self-similarity, but it didn't look trivial to me. So, before really getting to work on that, I decided to try again with the literature search. This time I used ChatGPT's new "Deep Research" feature. It thought about it for a long time, doing a bunch of searches, and eventually replied with a list of papers it thought might be promising. Most of them actually weren't, but one of them was an exact match. This 2019 paper by French mathematician Olivier Rozier contains a plot that looks exactly the same as mine! It was really fun to see it again in a different context, and Rozier does prove some self-similarity results. Rozier's paper also cites a 2007 paper by Yukihiro Hashimoto that has the same plot again. Neither Rozier's nor Hashimoto's plot is constructed the same way as mine, even though they look the same. Both of these papers build the plot starting with 2-adic numbers and only later map those to fractions. I would guess the 2-adic approach probably makes their proofs nicer, but jumping straight to fractions is likely to be easier if you've never seen p-adic numbers before (or if, like me, it's been long enough that you've forgotten most of what you learned about them!).

If you find something interesting in the plot — a nice pattern, a structure, something weird — please let me know! I'd love for this to spark your imagination and maybe even lead to some new discoveries. I think this plot is beautiful, and I hope you enjoy it too.

Thanks to Tatiana Moorier and Emmett Shear for reading drafts of this.


联系我们 contact @ memedata.com