0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【第3回】1に「初めて」着く回数を数えよう

0
Last updated at Posted at 2026-11-15

目次
https://qiita.com/Shamoo/items/c9e43a6f4034f58e1a7e

前の記事
https://qiita.com/Shamoo/items/821629c44440194ec28d

概要

5から始めると、普通のコラッツ操作では $5\to16\to8\to4\to2\to1$ の5回です。ところが計算を止めずに続けると、$1\to4\to2\to1$ と回って、8回目にも1に着きます。5は「5回で初到達」の欄にだけ入れたいですよね。今回は、1に着いた後の一周を引くことで、逆像の個数から総停止時間のヒストグラムを作ります。

一周した組をまとめて引く

奇数から次の奇数まで進む操作を $c$ と書きます。正奇数 $x$ に $3x+1$ を施し、奇数になるまで2で割ったものが $c(x)$ です。反復の回数が $s$、その間に2で割った総回数が $V$ なら、普通の操作は合わせて $s+V$ 回です。

正の整数 $N$ を決めます。$T_N(s,V)$ は、$N$ 以下の正奇数のうち、$c$ をちょうど $s$ 回適用すると1に着き、その間の除算回数が $V$ となる始点の個数です。途中で1に着いた始点も含めます。また $T_N(0,0)=1$ は始点1の分で、$V\ne0$ のときは $T_N(0,V)=0$ とします。正の $s$ に対して $V<s$ の場合も0です。

最終段より前に1を踏んだ軌道は、末尾が必ず $c(1)=1$ です。この一段では $3\cdot1+1=4$ を2で2回割ります。その一段を外せば $(s,V)$ が $(s-1,V-2)$ になり、始点は同じです。逆に、一段付け足すと元に戻ります。よって、$(s,V)$ で初めて1に着く始点の個数を $K_N(s,V)$ とすると

K_N(s,V)=T_N(s,V)-T_N(s-1,V-2)

です。途中で何周したかは調べなくて大丈夫。末尾の一周の有無だけで、引くべき始点をちょうど拾えます。

深さ2で実際に引いてみる

最後の二段を逆向きにたどります。最初の除算回数を $a_1$ とすると、始点は $x=(2^V-3-2^{a_1})/9$ です。ここでは候補 $a_1=1,\dots,V-1$ を入れ、正の整数になるものを拾います。

除算5回。 $2^5-3=29$ から $2,4,8,16$ を引くと、分子は $27,25,21,13$。9で割れるのは27だけなので、始点は3です。実際に $3\to5\to1$ の除算回数は1回と4回。一段で除算3回の逆像はないので、$K_{20}(2,5)=1-0=1$ です。

除算6回。 今度は $2^6-3=61$ から $2,4,8,16,32$ を引きます。分子 $59,57,53,45,29$ のうち、9で割れるのは45だけ。始点5は $5\to1\to1$ と進みます。一段で除算4回なら同じ始点5が入るので、$K_{20}(2,6)=1-1=0$。8回目の到達が差分で消えました。

総停止時間の表を作る

$M_N(t)$ を、$N$ 以下の正奇数で、普通のコラッツ操作の総停止時間がちょうど $t$ であるものの個数とします。$t=0$ は始点1の1個。$t\ge1$ では $V=t-s$ とおけばよく、各段で少なくとも一度は2で割るので $V\ge s$、つまり $s\le\lfloor t/2\rfloor$ です。

M_N(0)=1,\qquad
M_N(t)=\sum_{s=1}^{\lfloor t/2\rfloor}K_N(s,t-s)\quad(t\ge1).

例えば $N=20$ で $t=7$ なら、調べる組は $(1,6),(2,5),(3,4)$ の三つ。$(1,6)$ の始点は $(64-1)/3=21$ で範囲の外。$(2,5)$ は上で求めた3です。$(3,4)$ で、最後に初めて1へ入るなら、最後だけで少なくとも4回の除算が必要です。前二段にも各1回が必要なので、この組からは初到達できません。よって $M_{20}(7)=1$ です。

$N=20$ の全表はこうなります。例えば17は $17\to13\to5\to1$。除算回数が $2+3+4=9$、奇数から次の奇数までが3段なので、$t=12$ の欄です。

総停止時間 始点 個数
0 1 1
5 5 1
7 3 1
9 13 1
12 17 1
14 11 1
16 7 1
17 15 1
19 9 1
20 19 1

まだ着いていない始点も数えられる

時刻 $T$ を決めたら、奇数の総数から、その時刻までに着いた分を引きます。

D_N(T)=\left\lfloor\frac{N+1}{2}\right\rfloor-\sum_{t=0}^T M_N(t).

$D_N(T)$ は $N$ 以下の正奇数のうち、$T$ 回以内に1に着かなかった始点数です。例えば $D_{20}(12)=10-5=5$。時刻12で数えるので、12回目に着く17は到達済みです。この有限時刻で残った始点がその後どうなるかは、時刻を伸ばして初めて分かります。この例では $D_{20}(20)=0$ です。

図では、上段の棒が各時刻の初到達、下段の階段がその時刻を過ぎてもまだ残っている個数です。例えば12回目に17が着くと、下の階段は6から5へ一段下がります。横軸は、どちらも通常のコラッツ操作の回数です。

03_histogram_and_tail.png

図を作るPythonコード
from collections import Counter
from itertools import accumulate

import matplotlib.pyplot as plt
from matplotlib.ticker import MaxNLocator


def backward_histogram(bound, horizon):
    counts = Counter({0: 1})

    def visit(value, elapsed):
        for divisions in range(1, horizon - elapsed):
            numerator = 2**divisions * value - 1
            if numerator % 3:
                continue
            start = numerator // 3
            if start == 1:
                continue
            time = elapsed + 1 + divisions
            if start <= bound:
                counts[time] += 1
            visit(start, time)

    visit(1, 0)
    return counts


def forward_histogram(bound, horizon):
    counts = Counter()
    for start in range(1, bound + 1, 2):
        value = start
        for time in range(horizon + 1):
            if value == 1:
                counts[time] += 1
                break
            value = value // 2 if value % 2 == 0 else 3 * value + 1
    return counts


bound, horizon = 20, 20
counts = backward_histogram(bound, horizon)
assert counts == forward_histogram(bound, horizon)
times = list(range(horizon + 1))
arrivals = [counts[time] for time in times]
remaining = [(bound + 1)//2 - n for n in accumulate(arrivals)]
assert remaining[12] == 5 and remaining[-1] == 0

fig, (top, bottom) = plt.subplots(2, 1, sharex=True, figsize=(8, 5), layout="constrained")
top.bar(times, arrivals, color="#2b6a9e", width=0.68)
top.set(ylabel="First arrivals", title="Odd starts from 1 to 20")
bottom.step(times, remaining, where="post", color="#a44528", linewidth=2.4)
bottom.scatter([12], [remaining[12]], color="#a44528", zorder=3)
bottom.annotate("5 still remaining", (12, 5), xytext=(13, 7),
                arrowprops={"arrowstyle": "-", "color": "#596477"})
bottom.set(xlabel="Ordinary Collatz steps", ylabel="Remaining", ylim=(-0.4, 10.5))
for axis in (top, bottom):
    axis.grid(axis="y", alpha=0.25)
    axis.set_axisbelow(True)
    axis.yaxis.set_major_locator(MaxNLocator(integer=True))
    axis.spines[["right", "top"]].set_visible(False)
bottom.set_xticks(range(0, horizon + 1, 2))
fig.savefig("03_histogram_and_tail.png", dpi=175)
plt.close(fig)

順方向の集計と逆方向の集計は、折りたたみのコードに両方入れました。逆向きでは初手の自己ループを外し、時刻の上限までたどります。始点の上限 $N$ は候補を表に入れるときに適用します。例えば19は、途中で $29>20$ を通ってから1に着くので、途中の値を20で切ると落としてしまいます。

この先につながる話

規模を大きくするとヒストグラムに細かい振動が出ます。第11回では、103を通る群と通らない群、始点上限の境界にかかる層を比べます。第15回は、残っている個数をある一つの等差数列で測ると、どうして全体の到達と関係するのか、という話です。

参考

  • 岡 將太・岡 万桜「コラッツ予想のステップ数(総停止時間)について」第4節および続編第5節。

次回は、ゴールを1からほかの奇数へ動かし、深さ2の分子の零点から到達を判定します。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?