题目
n = 17 条通道(problem.toml 中的 [params] channels)上的比较器网络,通道编号为 0 … 16,是一个由比较器 [a, b] 组成的列表,其中 0 ≤ a < b ≤ 16。比较器把通道 a 和 b 上两个值中的较小者放到通道 a,较大者放到通道 b。比较器按列表顺序依次作用,对每个输入都是同一个顺序。如果对来自一个全序集的任意 17 个值的输入,输出值都按通道编号单调不减,这个网络就是排序网络。
找出一个比较器尽可能少的 17 通道排序网络。得分为比较器的个数。深度(并行层数)不受限制,也不计分。
得分是整数,因此低于基线的下一个可能取值是 70。
最小可能的个数 S(17) 未知。上界 71 即下面的基线。下界:S(12) = 39(Harder,arXiv:2012.04400),加上 Van Voorhis 的界 S(n) ≥ S(n − 1) + ⌈log₂ n⌉(Harder 中重述为引理 17),给出 S(17) ≥ 39 + 4 + 4 + 4 + 4 + 5 = 60。Dobbelaere 的表列出的下界为 63(2025 年更新),一篇预印本(Tomar,2026)声称为 64;这两个证明在此都未经核验。这些界与计分无关。
为什么重要
给 n 个输入排序所需的最少比较器数,就是 Bose–Nelson 排序问题(Bose 和 Nelson,A sorting problem,JACM 9 (1962) 282–296)。精确值只在 n ≤ 12 时已知(OEIS A003075):n = 9 和 10 由 Codish、Cruz-Filipe、Frank 和 Schneider-Kamp(2014)确定,n = 11 和 12 由 Harder(2020)确定,并附有经计算机检查的证书。排序网络对每个输入都做同样的比较,因此被用于硬件排序和并行排序,小网络也是构造大网络的部件(Valsalam 和 Miikkulainen,2013,§1)。
对 17 个输入,Valsalam 和 Miikkulainen(JMLR 14,2013,303–331)列出此前的最好规模为 73(表 2),并报告了一个含 71 个比较器的网络(表 4,图 17)。Dobbelaere 的已知最小排序网络表对 17 个输入列出 71 个比较器(12 层)。含 70 个或更少比较器的 17 输入排序网络,比这些来源中的所有网络都小。
Few Shots 上的推进
从预设基线开始,每一行是一次经验证器复算的有效突破
- #071预设基线
- #1?等待挑战者
证书格式
- 文件名为
certificate.json,形如 {"comparators": [[0, 11], [1, 15], …]},不含其他键。 comparators 是由 1 … 1000 个比较器([params] max_comparators)组成的列表,按执行顺序排列。- 每个比较器是恰好由两个 JSON 整数组成的列表
[a, b],满足 0 ≤ a < b ≤ 16。通道从 0 开始编号;Valsalam 和 Miikkulainen 从 1 开始编号,因此要减 1。布尔值、字符串、小数、指数形式、NaN 和 Infinity 都会被拒绝;-0 视为整数 0。 - 允许重复的比较器和从不交换任何东西的比较器,每一个都计入个数。
- 得分为列表的长度,是一个整数,例如
"71"。 - 验证器检查全部 2^17 = 131,072 个由 0 和 1 组成的输入,根据 0-1 原理这就足够了(Knuth,*The Art of Computer Programming*,第 3 卷,§5.3.4,定理 Z;另见 Harder,§2)。检查是穷举且精确的:每条通道存为一个 131,072 位的整数,每个 0-1 输入占一位,一个比较器就是一次按位与(通道 a)和按位或(通道 b)。输出通道 j 必须恰好在含至少 17 − j 个 1 的那些输入上为 1。
- 文件为 UTF-8 编码的 JSON,不带字节顺序标记,大小不超过 65,536 字节,嵌套不超过 8 层,整数不超过 18 位,不含重复键(键在 JSON 反转义之后比较)。
- 规范形式。设 c_1, …, c_m 为按列出顺序的比较器。
- 列表的层:对每条通道 i,先令 last[i] = −1。按列表顺序处理每个比较器 [a, b]:令 level = 1 + max(last[a], last[b]),把 [a, b] 加到第
level 层(层从 0 开始编号),并令 last[a] = last[b] = level。然后把每层内的比较器按 a 递增排序(同一层的比较器不共用通道)。结果是一个层的列表,每层是若干对 [a, b] 组成的列表。 - 镜像:把每个 [a, b] 换成 [16 − b, 16 − a]、顺序不变得到的列表。它是排序网络当且仅当原列表是排序网络,比较器个数相同。
- 取列表的层和其镜像的层,按字典序保留较小的那个:从第一层起逐层比较;两层之间逐对比较;两对之间先比 a,再比 b;一个列表若是另一个列表的真前缀,则它较小。(这就是 Python 对嵌套列表的排序。)
- 规范对象为
{"channels": 17, "layers": L},L 为保留下来的层列表。 canonical_hash 是该对象写成 JSON 后的小写十六进制 SHA-256:键按排序后的顺序(先 channels,后 layers),没有任何空白,整数用普通十进制,ASCII 字节,末尾没有换行;在 Python 中为 json.dumps(obj, sort_keys=True, separators=(",", ":"), ensure_ascii=True).encode("ascii")。
因此,在不让一个比较器越过另一个与它共用通道的比较器的前提下,重排不相交通道上的比较器不改变哈希,一个网络和它的镜像哈希相同。网络之间的其他等价关系不会被识别;与纪录打平,无论哪种情况都不算改进。
算例(不是排序网络,只用来演示计算):列表 [[5,9],[0,1],[1,2],[3,4]] 的层为 [[[0,1],[3,4],[5,9]],[[1,2]]];其镜像 [[7,11],[15,16],[14,15],[12,13]] 的层为 [[[7,11],[12,13],[15,16]],[[14,15]]];前者较小,因此被哈希的字节为 {"channels":17,"layers":[[[0,1],[3,4],[5,9]],[[1,2]]]},SHA-256 为 c26d7f99be61e7e5d87924e6370f6b563e4c8146f73497a5dce931f8f3fc6e9e。对基线,镜像给出较小的层,canonical_hash 为 7899e5f61628b897666dcaf1d556c99adf37005a6d4692a266ca927fcda6df97。
基线
71 个比较器,即 Valsalam 和 Miikkulainen(2013,表 4 和图 17)报告的规模。Dobbelaere 的表把这一规模上界归于 Baddar(2009),但未核对该论文中是否有 17 输入的网络;谁最先得到 71,在此未经确认。
baseline/certificate.json 是 Bert Dobbelaere 的 SorterHunter 仓库在提交 8ba90df607cbdc339409e0b173b5a2ffd60fc911 时 Sort_17_71_12.json 中的 nw 列表(71 个比较器,12 层;文件的 SHA-256 为 dc139714281074c8fef1ce3cc2835aee8b5e95cc4fe8067cef27454dbd9efbcc),原样复制到键 comparators 下。它就是 Dobbelaere 的表中给出的 71 比较器网络,与 Valsalam 和 Miikkulainen 的图 17 规模相同,但只有 12 层而不是 17 层。数据采用 MIT 许可证(© 2017 bertdobbelaere);完整声明见 baseline/LICENSE-SorterHunter.txt,它适用于基线证书,不适用于提交的 shots。
复现方法:
python3 problems/p011-sorting-network-17/verify/verify.py problems/p011-sorting-network-17/baseline
Problem
A comparator network on n = 17 channels ([params] channels in problem.toml), numbered 0 … 16, is a list of comparators [a, b] with 0 ≤ a < b ≤ 16. A comparator puts the minimum of the values on channels a and b on channel a and the maximum on channel b. The comparators act one after another in the listed order, the same order for every input. The network is a sorting network if, for every input of 17 values from a totally ordered set, the output values are non-decreasing in channel number.
Find a sorting network on 17 channels with as few comparators as possible. The score is the number of comparators. Depth (the number of parallel layers) is not restricted and not scored.
The score is an integer, so the next possible score below the baseline is 70.
The least possible number S(17) is not known. The upper bound 71 is the baseline below. Lower bounds: S(12) = 39 (Harder, arXiv:2012.04400) and the bound S(n) ≥ S(n − 1) + ⌈log₂ n⌉ of Van Voorhis, restated as Lemma 17 in Harder, give S(17) ≥ 39 + 4 + 4 + 4 + 4 + 5 = 60. Dobbelaere's table lists the lower bound 63 (updated in 2025), and a preprint (Tomar, 2026) claims 64; neither proof is checked here. These bounds play no part in scoring.
Why it matters
The least number of comparators that sorts n inputs is the Bose–Nelson sorting problem (Bose and Nelson, A sorting problem, JACM 9 (1962) 282–296). Exact values are known only for n ≤ 12 (OEIS A003075): n = 9 and 10 by Codish, Cruz-Filipe, Frank and Schneider-Kamp (2014), n = 11 and 12 by Harder (2020), with a computer-checked certificate. A sorting network performs the same comparisons for every input, so it is used for sorting in hardware and in parallel, and small networks are building blocks for larger ones (Valsalam and Miikkulainen, 2013, §1).
For 17 inputs, Valsalam and Miikkulainen (JMLR 14, 2013, 303–331) list 73 as the previous best size (Table 2) and report a network with 71 comparators (Table 4, Figure 17). Dobbelaere's table of the smallest known sorting networks lists 71 comparators (12 layers) for 17 inputs. A sorting network on 17 inputs with 70 comparators or fewer is smaller than every network in these sources.
Progress on Few Shots
From the preset baseline, one row per valid breakthrough recomputed by the verifier
- #071Preset baseline
- #1?Awaiting a challenger
Certificate
- File name
certificate.json, shaped like {"comparators": [[0, 11], [1, 15], …]}, with no other keys. comparators is a list of 1 … 1000 comparators ([params] max_comparators), in execution order.- Each comparator is a list of exactly two JSON integers
[a, b] with 0 ≤ a < b ≤ 16. Channels are numbered from 0; Valsalam and Miikkulainen print theirs from 1, so subtract 1. Booleans, strings, fractions, exponents, NaN and Infinity are rejected; -0 is the integer 0. - Repeated comparators and comparators that never exchange anything are allowed, and each one is counted.
- The score is the length of the list, an integer, for example
"71". - The verifier checks all 2^17 = 131,072 inputs of 0s and 1s, which suffices by the zero-one principle (Knuth, *The Art of Computer Programming*, vol. 3, §5.3.4, Theorem Z; also Harder, §2). The check is exhaustive and exact: each channel is held as a 131,072-bit integer, one bit per 0-1 input, and a comparator is a bitwise AND (channel a) and OR (channel b). Output channel j must be 1 on exactly the inputs with at least 17 − j ones.
- The file is UTF-8 JSON without a byte order mark, at most 65,536 bytes, nested at most 8 levels, with integers of at most 18 digits and no duplicate keys (keys are compared after JSON unescaping).
- Canonical form. Let c_1, …, c_m be the comparators as listed.
- Layers of a list: start with last[i] = −1 for every channel i. For each comparator [a, b] in list order, let level = 1 + max(last[a], last[b]), append [a, b] to layer number
level (layers are numbered from 0), and set last[a] = last[b] = level. Then sort the comparators inside each layer in increasing order of a (comparators in one layer share no channel). The result is a list of layers, each a list of pairs [a, b]. - Mirror image: the list with every [a, b] replaced by [16 − b, 16 − a], in the same order. It is a sorting network exactly when the original is, with the same number of comparators.
- Take the layers of the list and the layers of its mirror image, and keep the smaller of the two in lexicographic order: compare layer by layer from the first; two layers compare pair by pair; two pairs compare by a, then by b; a list that is a proper prefix of another is smaller. (This is Python's ordering of nested lists.)
- The canonical object is
{"channels": 17, "layers": L} with L the kept list of layers. canonical_hash is the lowercase hex SHA-256 of that object written as JSON with the keys in sorted order (channels, then layers), no whitespace at all, integers in plain decimal, ASCII bytes, no trailing newline; in Python, json.dumps(obj, sort_keys=True, separators=(",", ":"), ensure_ascii=True).encode("ascii").
So reordering comparators on disjoint channels, without moving a comparator past another that shares a channel with it, does not change the hash, and a network and its mirror image hash the same. Other equivalences between networks are not detected; a tie with the record is not an improvement either way.
Worked example (not a sorting network; it only shows the computation): the list [[5,9],[0,1],[1,2],[3,4]] has layers [[[0,1],[3,4],[5,9]],[[1,2]]]; its mirror image [[7,11],[15,16],[14,15],[12,13]] has layers [[[7,11],[12,13],[15,16]],[[14,15]]]; the first is smaller, so the hashed bytes are {"channels":17,"layers":[[[0,1],[3,4],[5,9]],[[1,2]]]}, with SHA-256 c26d7f99be61e7e5d87924e6370f6b563e4c8146f73497a5dce931f8f3fc6e9e. For the baseline the mirror image gives the smaller layers, and canonical_hash is 7899e5f61628b897666dcaf1d556c99adf37005a6d4692a266ca927fcda6df97.
Baseline
71 comparators, the size reported by Valsalam and Miikkulainen (2013, Table 4 and Figure 17). Dobbelaere's table credits the size upper bound to Baddar (2009), whose thesis was not checked for a 17-input network; who found 71 first is not confirmed here.
baseline/certificate.json is the nw list of Sort_17_71_12.json in Bert Dobbelaere's SorterHunter repository at commit 8ba90df607cbdc339409e0b173b5a2ffd60fc911 (71 comparators, 12 layers; SHA-256 of the file dc139714281074c8fef1ce3cc2835aee8b5e95cc4fe8067cef27454dbd9efbcc), copied unchanged under the key comparators. It is the 71-comparator network shown in Dobbelaere's table, a network of the same size as Figure 17 of Valsalam and Miikkulainen but with 12 layers instead of 17. The data is under the MIT licence (© 2017 bertdobbelaere); the full notice is in baseline/LICENSE-SorterHunter.txt and applies to the baseline certificate, not to submitted shots.
To reproduce:
python3 problems/p011-sorting-network-17/verify/verify.py problems/p011-sorting-network-17/baseline