SymPy | Python中的 Partition.RGS_enum()
Partition.RGS_enum() :RGS_enum()是一个 sympy Python库函数,它计算限制增长字符串的总数(字符串,其中 a[i] 是元素 i 出现的块) ,这对于大小为 n 的超集是可能的。
限制增长的字符串——字符串中的每个字符, a i导致对应元素所属的块 (B i )。
Syntax : sympy.combinatorics.partitions.Partition.RGS_enum()
Return : total number of restricted growth strings, possible for a superset of size n.
代码 #1:RGS_enum() 示例
# Python code explaining
# SymPy.RGS_enum()
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.partitions import RGS_enum
# Using from sympy.combinatorics.partitions.Partition.RGS_enum() method
p = RGS_enum(4)
q = RGS_enum(9)
print ("no. of strings possible for size 4: ", p)
print ("no. of strings possible for size 9: ", q)
输出 :
no. of strings possible for size 4: 15
no. of strings possible for size 9: 203
代码 #2:RGS_enum() 示例
# Python code explaining
# SymPy.RGS_enum()
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.partitions import RGS_enum
# Using from sympy.combinatorics.partitions.Partition.RGS_enum() method
p = RGS_enum(20)
q = RGS_enum(-1)
print ("no. of strings possible for size 20 ", p)
print ("no. of strings possible for size -1: ", q)
输出 :
no. of strings possible for size 20 51724158235372
no. of strings possible for size -1: 0