Groupings[n,k]
给出 1,…,n 在一次取 k 个元素情况下所有可能的分组列表.
Groupings[{a1,…,an},k]
给出 a1,…,an 在一次取 k 个元素情况下所有可能的分组.
Groupings[{{a1,a2,…},{b1,b2,…},…},k]
给出列表 ai,bi,… 在一次取 k 个元素情况下所有可能的分组组合.
Groupings[aspec,fk]
给出 aspec 在一次取 k 个元素情况下所有可能的分组,同时在每个层应用函数 f.
Groupings[aspec,{f1k1,f2k2,…}]
给出所有可能的分组,其中函数 fi 被应用于元素 ki.
Groupings[aspec,{{f1k1,m1},{f2k2,m2},…}]
最多允许 mi 次把 fi 应用到 ki 元素的分组.
Groupings[aspec,kspec,h]
把函数 h 封装到每个产生的分组.
Groupings
Groupings[n,k]
给出 1,…,n 在一次取 k 个元素情况下所有可能的分组列表.
Groupings[{a1,…,an},k]
给出 a1,…,an 在一次取 k 个元素情况下所有可能的分组.
Groupings[{{a1,a2,…},{b1,b2,…},…},k]
给出列表 ai,bi,… 在一次取 k 个元素情况下所有可能的分组组合.
Groupings[aspec,fk]
给出 aspec 在一次取 k 个元素情况下所有可能的分组,同时在每个层应用函数 f.
Groupings[aspec,{f1k1,f2k2,…}]
给出所有可能的分组,其中函数 fi 被应用于元素 ki.
Groupings[aspec,{{f1k1,m1},{f2k2,m2},…}]
最多允许 mi 次把 fi 应用到 ki 元素的分组.
Groupings[aspec,kspec,h]
把函数 h 封装到每个产生的分组.
范例
打开所有单元 关闭所有单元基本范例 (5)
Groupings[4, 2]TreeForm /@ %Groupings[{a, b, c, d, e}, 3]Groupings[{{1, 2, 3, 4, 5}, {a, b, c, d, e}}, 3]Groupings[Tuples[{a, b}, 3], 2]Groupings[{a, b, c, d}, {foo -> 3, bar -> 2}]范围 (10)
Groupings[Tuples[{a, b, c}, 3], 2]Groupings[Permutations[{a, a, b, b}], {2, 3, 4}]Groupings[{a, b, c}, CircleTimes -> 2]Groupings[{a, b, c, d}, Wedge -> 2]Groupings[{a}, Square -> 1]Groupings[{a, b}, {Not -> 1, Wedge -> 2}]Groupings[{a, b}, {Not -> 1, Wedge -> 2, Vee -> 2}]Groupings[{a, b, b}, {head1, head2} -> 2]Groupings[Subsets[{a, b, c, d}, {4}], head -> {2, 3}]Groupings[Permutations[{a, a, a, b}], {head1 -> 2, head2 -> 3}]Groupings 默认构建给定元数的所有可能性:
Groupings[Table["∘", 6], {Style[f, Blue] -> 2, Style[g, Red] -> 3}]//ShortGroupings[Table["∘", 6], {{Style[f, Blue] -> 2, 2}, {Style[g, Red] -> 3, 2}}]缺省情况下,Groupings 返回树的分支的所有可能的排列:
Groupings[{a, a, a, a}, 2]TreeForm /@ %Groupings[{a, a, a, a}, {2, Orderless}]TreeForm /@ %TreeForm /@ Groupings[{a, a, a, b}, {head1 -> {2, Orderless}, head2 -> 3}]应用 (8)
列出可用符号 s 的 4 个副本构造的所有可能的一元应用表达式:
Groupings[Table[s, 4], Construct -> 2]Groupings[Table[s, 5], Construct -> 3]Groupings[Table[s, 6], Construct -> 3]Groupings[Table[s,n],Constructk] 将为 {},除非 n≥k 且 Mod[n,k-1]==1:
n = 9;
k = 5;
Mod[n, k - 1]exprs = Groupings[Table[s, n], Construct -> k]m = (n - 1) / (k - 1)有 Binomial[k m,m]/n 个表达式:
Binomial[k m, m] / nLength[exprs]Groupings[{a, b, c}, Plus -> 2, HoldForm]//ColumnGroupings[Permutations[{a, b, c}], Plus -> 2, HoldForm]//ColumnGroupings[{1, 1, 1}, {Plus -> 2, Times -> 2}, HoldForm]ReleaseHold[%]求用二元运算 +,* 对七个 1 进行组合的所有可能的结果的频次:
Groupings[Table[1, 7], {Plus -> 2, Times -> 2}]//Histogram对于给定整数 n,通过 +,* 来构建 n 所需的最少的 1 的数量被称作 n 的复杂度. 例如,12 的复杂度是 7:
Table[k -> Position[Groupings[Table[1, k], {Plus -> 2, Times -> 2}], 12], {k, 7}]Groupings[Table[1, 7], {Plus -> 2, Times -> 2}, HoldForm][[905]]Groupings[Tuples[{x, y}, 3], {Plus, Times, Power} -> 2]Groupings[Tuples[{x, y}, 3], {Plus, Times, Power} -> 2, HoldForm]共有 3840 种形式来组合整数 1、1、5、8 和二元运算 +、-、*、/:
Length[list = Groupings[Permutations[{1, 1, 5, 8}], {Plus, Subtract, Times, Divide} -> 2, HoldForm]]RandomSample[list, 10]results = ReleaseHold[list];Cases[Thread[Equal[list, results]], _ == 10]TakeLargestBy[Tally[results], Last, 5]Length[props = Groupings[{x, !x, y, !y}, {And, Nand, Or, Nor, Xor} -> 2]]bfs1 = DeleteDuplicates[BooleanConvert /@ props]bfs2 = BooleanFunction[#, {x, y}]& /@ Range[0, 15]Sort[bfs1] === Sort[bfs2]Length[props = Groupings[{x, y, !x, !y}, {And, Nand, Or, Nor} -> 2]]bfs1 = DeleteDuplicates[BooleanConvert /@ props]bfs2 = BooleanFunction[#, {x, y}]& /@ Range[0, 15]Sort[bfs1] === Sort[bfs2]另外,还有一种更简单的结构,即把一元的 Not 作为一个单独的词头:
bfs3 = DeleteDuplicates[BooleanConvert /@ Groupings[{x, y, x, y}, {{And, Or} -> 2, Not -> 1}]]Sort[bfs3] === Sort[bfs2]用二元头 Plus 和 Times 构建包含这六个复数的所有表达式:
Most@Exp[2 Pi I Subdivide[0, 1, 6]]groupings6 = Groupings[%, {Times -> 2, Plus -> 2}];ComplexListPlot[groupings6, PlotStyle -> PointSize[0.02]]Most@Exp[2 Pi I Subdivide[0, 1, 7]]groupings7 = Groupings[%, {Times -> 2, Plus -> 2}];ComplexListPlot[groupings7, PlotStyle -> PointSize[0.01]]属性和关系 (6)
对于 n≥2,Groupings[{a},n] 返回 {a}:
Groupings[{a}, 2]Groupings[{a}, 3]Groupings[{a}, 1]对于 n≥2,Groupings[{a1,…,an},n] 返回 {{a1,…,an}} :
Groupings[{a, b}, 2]Groupings[{a, b, c}, 3]Groupings[{a}, 1]具有元数 k 的头和 n 个叶子的树的树有 (n-1)/(k-1) 个内部结点,因此该数字必须是非负整数:
Groupings[5, h -> 3](5 - 1) / (3 - 1)Groupings[5, h -> 4](5 - 1) / (4 - 1)具体来讲,意味着如果 k>n>1,Groupings[n,k] 给出 {}:
Groupings[3, 5]Groupings[1, 5]具有 n 个叶的二进制分组的数目由第 (n-1) 个卡塔兰数给出:
Table[Length[Groupings[n, 2]] === CatalanNumber[n - 1], {n, 1, 10}]Table[Length[Groupings[n, {1, 2}]] == 2 ^ (2n - 1)CatalanNumber[n - 1], {n, 1, 6}]具有 n 个叶的 k 进制分组的数目与 Fuss–Catalan 数相关:
FussCatalanNumber[n_, k_] := Binomial[k n, n] / ((k - 1)n + 1);k = 3;
ns = Range[1, 15, k - 1]Length[Groupings[#, k]]& /@ nsFussCatalanNumber[# - 1, k]& /@ Range[Length[ns]]k = 4;
ns = Range[1, 19, k - 1]Length[Groupings[#, k]]& /@ nsFussCatalanNumber[# - 1, k]& /@ Range[Length[ns]]Groupings[{a, b, c, d, e, f, g, h, i, j}, 4]DeleteDuplicates[Level[#, {-1}]& /@ %]可能存在的问题 (1)
这被解释为表示元数为 3 的头 h 与元数为 2 的头 List 的存在:
Groupings[5, {h -> 3, 2}]% === Groupings[5, {h -> 3, List -> 2}]为了使得元数为 3 的头 h 最多出现两次,使用更多一层列表:
Groupings[5, {{h -> 3, 2}}]文本
Wolfram Research (2016),Groupings,Wolfram 语言函数,https://reference.wolfram.com/language/ref/Groupings.html (更新于 2025 年).
CMS
Wolfram 语言. 2016. "Groupings." Wolfram 语言与系统参考资料中心. Wolfram Research. 最新版本 2025. https://reference.wolfram.com/language/ref/Groupings.html.
APA
Wolfram 语言. (2016). Groupings. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/Groupings.html 年
BibTeX
@misc{reference.wolfram_2026_groupings, author="Wolfram Research", title="{Groupings}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/Groupings.html}", note=[Accessed: 17-November-2026]}
BibLaTeX
@online{reference.wolfram_2026_groupings, organization={Wolfram Research}, title={Groupings}, year={2025}, url={https://reference.wolfram.com/language/ref/Groupings.html}, note=[Accessed: 17-November-2026]}