Problem.
定义函数
求 \(-\log_2(f(4))\)。
Solution.
定义 \(g(x)=-\log_2(f(x))\)。
一个非常类似燃烧数函数的函数。尝试把他画出来。

显然这是一个分段函数,每段都有它自己的长度。
\([0,1]\) 被分为两段,\(2\) 和 \(3\) 各占 \(\frac12\)。
\([1,2]\) 被分为六段(两种不同长度),\(4,5\) 各占 \(\frac14\)(总占 \(\frac12\)),\(6,7,8,9\) 各占 \(\frac18\)(总占 \(\frac12\))。因此 \(g(2)=10\)。
尝试使用相同的方法计算 \(g(3)\)。这也就意味着 \([2,3]\) 被分解为多段(六种不同长度,这与 \([1,2]\) 中的段数对应)。我们可以使用贡献法统计答案。列出表格:
| x 的下界 | 区间长度 \(= 2^{-g(x-1)}\) | 区间内的 \(g\) | 贡献 \(= \text{区间长度}\times 2^{g}\) |
|---|---|---|---|
| \(-\infty\) | \(\text{N/A}\) | \(\text{N/A}\) | \(10\) |
| \(1\) | \(\tfrac{1}{4}\) | \(4\) | \(2^{2}\) |
| \(\tfrac{5}{4}\) | \(\tfrac{1}{4}\) | \(5\) | \(2^{3}\) |
| \(\tfrac{3}{2}\) | \(\tfrac{1}{8}\) | \(6\) | \(2^{3}\) |
| \(\tfrac{13}{8}\) | \(\tfrac{1}{8}\) | \(7\) | \(2^{4}\) |
| \(\tfrac{7}{4}\) | \(\tfrac{1}{8}\) | \(8\) | \(2^{5}\) |
| \(\tfrac{15}{8}\) | \(\tfrac{1}{8}\) | \(9\) | \(2^{6}\) |
这样我们可以得到 \(g(3)=2^6+2^5+2^4+2^3+2^3+2^2+10=142\)。
我们还注意到对于相同的 \(g(x-2)\)(假设位于 \([a,b)\)),\(g(x-1)\) 里面的 \(x\) 增加的贡献是一个等比数列,可以通过 \(x=a\) 处 \(g(x-1)\) 增加的贡献快速求出。对于上述表格就是:
| x 的下界 | 区间长度 \(= 2^{-g(x-1)}\) | 区间内的 \(g\) | 贡献 \(= \text{区间长度}\times 2^{g}\) |
|---|---|---|---|
| \(1\) | \(\tfrac{1}{4}\) | \(4\) | \(2^{2}\) |
| \(\left(\times 2:\,[1,\frac32\right)\) | \(\tfrac{1}{4}\ \text{each}\) | \(\times(2^2-1)=2^4-2^2\) | |
| \(\tfrac{3}{2}\) | \(\tfrac{1}{8}\) | \(6\) | \(2^{3}\) |
| \(\left(\times 4:\,[\frac32,2\right)\) | \(\tfrac{1}{8}\ \text{each}\) | \(\times(2^4-1)=2^7-2^3\) |
这样我们还是可以得到 \(g(3)=g(2)+(2^7-2^3)+(2^4-2^2)=2^7+14=142\)。
我们可以用同样的方法计算 \(g(4)\)。最后一列省略 \(\times(2^m-1)\)。
| x 的下界 | 区间长度 \(= 2^{-g(x-1)}\) | 区间内的 \(g\) | 贡献 \(= \text{区间长度}\times 2^{g}\) |
|---|---|---|---|
| \(2\) | \(\tfrac{1}{16}\) | \(10\) | \(2^{6}\) |
| \(\left(\times 4:\,[2,\tfrac{9}{4})\right)\) | \(\tfrac{1}{16}\ \text{each}\) | \(2^{10}-2^{6}\) | |
| \(\tfrac{9}{4}\) | \(\tfrac{1}{32}\) | \(14\) | \(2^{9}\) |
| \(\left(\times 8:\,[\tfrac{9}{4},\tfrac{5}{2})\right)\) | \(\tfrac{1}{32}\ \text{each}\) | \(2^{17}-2^{9}\) | |
| \(\tfrac{5}{2}\) | \(\tfrac{1}{64}\) | \(22\) | \(2^{16}\) |
| \(\left(\times 8:\,[\tfrac{5}{2},\tfrac{21}{8})\right)\) | \(\tfrac{1}{64}\ \text{each}\) | \(2^{24}-2^{16}\) | |
| \(\tfrac{21}{8}\) | \(\tfrac{1}{128}\) | \(30\) | \(2^{23}\) |
| \(\left(\times 16:\,[\tfrac{21}{8},\tfrac{11}{4})\right)\) | \(\tfrac{1}{128}\ \text{each}\) | \(2^{39}-2^{23}\) | |
| \(\tfrac{11}{4}\) | \(\tfrac{1}{256}\) | \(46\) | \(2^{38}\) |
| \(\left(\times 32:\,[\tfrac{11}{4},\tfrac{23}{8})\right)\) | \(\tfrac{1}{256}\ \text{each}\) | \(2^{70}-2^{38}\) | |
| \(\tfrac{23}{8}\) | \(\tfrac{1}{512}\) | \(78\) | \(2^{69}\) |
| \(\left(\times 64:\,[\tfrac{23}{8},3)\right)\) | \(\tfrac{1}{512}\ \text{each}\) | \(2^{133}-2^{69}\) |
因此 \(g(4)=2^{133}+2^{69}+2^{38}+2^{23}+2^{16}+2^9-2^6+g(3)=\boxed{2^{133}+2^{69}+2^{38}+2^{23}+2^{16}+590}\)。
扩展
想要算出 \(g(5)\),我们只需要知道 \([2,3]\) 中 \(g\) 的阶梯是怎样的。上表中有写:

增长的临界点是这样的:
[2, 33/16, 17/8, 35/16, 9/4, 73/32, 37/16, 75/32,19/8, 77/32, 39/16, 79/32, 5/2, 161/64, 81/32,
163/64, 41/16, 165/64, 83/32, 167/64, 21/8, 337/128, 169/64, 339/128, 85/32, 341/128, 171/64,
343/128, 43/16, 345/128, 173/64, 347/128, 87/32, 349/128, 175/64, 351/128, 11/4, 705/256, 353/128,
707/256, 177/64, 709/256, 355/128, 711/256, 89/32, 713/256, 357/128, 715/256, 179/64, 717/256,
359/128, 719/256, 45/16, 721/256, 361/128, 723/256, 181/64, 725/256, 363/128, 727/256,
91/32, 729/256, 365/128, 731/256, 183/64, 733/256, 367/128, 735/256, 23/8, 1473/512,
737/256, 1475/512, 369/128, 1477/512, 739/256, 1479/512, 185/64, 1481/512, 741/256, 1483/512,
371/128, 1485/512, 743/256, 1487/512, 93/32, 1489/512, 745/256, 1491/512, 373/128, 1493/512,
747/256, 1495/512, 187/64, 1497/512, 749/256, 1499/512, 375/128, 1501/512, 751/256, 1503/512,
47/16, 1505/512, 753/256, 1507/512, 377/128, 1509/512, 755/256, 1511/512, 189/64, 1513/512,
757/256, 1515/512, 379/128, 1517/512, 759/256, 1519/512, 95/32, 1521/512, 761/256, 1523/512,
381/128, 1525/512, 763/256, 1527/512, 191/64, 1529/512, 765/256, 1531/512, 383/128, 1533/512, 767/256, 1535/512]
我们需要对每一段计算出贡献。先写代码:
f(x)=if(x<0,1/2,f(x-f(x-1))/2);
count=0;
arr=Vec(0,132);
last_i=1024;
last_fi=1/1024;
for(i=1024,1536,if(f(i/512)!=last_fi,count=count+1;arr[count]=last_i/512;last_i=i;last_fi=f(i/512)));
arr
得到上方增长的临界点。再写代码:
arr = ...
def compute():
start = 10
ret_pos = [133,69,38,23,16,9,6,3,2,1]
ret_neg = []
glb = 142
arr.append(3)
for i in range(len(arr)):
lb = arr[i]
if lb == 3: break
contrib = glb - start
count_len = round((arr[i + 1] - arr[i]) * 2**start)
ret_pos.append(count_len + contrib)
ret_neg.append(contrib)
start = start + 1
glb += count_len
for i in range(len(ret_pos)):
try:
ret_neg.remove(ret_pos[i] - 1)
ret_pos[i] -= 1
except:
pass
ret_pos.sort(reverse=True)
return (ret_pos, ret_neg)
(pos, neg) = compute()
assert len(neg) == 0
for a in pos[:-1]: print(f"2^{{%d}} +" % a, end=" ")
print("2^%d" % pos[-1])
得到结果
注意到最大的那个幂次刚好等于 \(g(4)-g(3)+1\)。这点在 \(g(4)\) 同样成立:\(133=142-10+1\)。这个的证明可以通过表格的最后一行发现。
浙公网安备 33010602011771号