本文整理汇总了Python中sage.combinat.partition.Partition.dominates方法的典型用法代码示例。如果您正苦于以下问题:Python Partition.dominates方法的具体用法?Python Partition.dominates怎么用?Python Partition.dominates使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.combinat.partition.Partition
的用法示例。
在下文中一共展示了Partition.dominates方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: is_gale_ryser
# 需要导入模块: from sage.combinat.partition import Partition [as 别名]
# 或者: from sage.combinat.partition.Partition import dominates [as 别名]
def is_gale_ryser(r,s):
r"""
Tests whether the given sequences satisfy the condition
of the Gale-Ryser theorem.
Given a binary matrix `B` of dimension `n\times m`, the
vector of row sums is defined as the vector whose
`i^{\mbox{th}}` component is equal to the sum of the `i^{\mbox{th}}`
row in `A`. The vector of column sums is defined similarly.
If, given a binary matrix, these two vectors are easy to compute,
the Gale-Ryser theorem lets us decide whether, given two
non-negative vectors `r,s`, there exists a binary matrix
whose row/colum sums vectors are `r` and `s`.
This functions answers accordingly.
INPUT:
- ``r``, ``s`` -- lists of non-negative integers.
ALGORITHM:
Without loss of generality, we can assume that:
- The two given sequences do not contain any `0` ( which would
correspond to an empty column/row )
- The two given sequences are ordered in decreasing order
(reordering the sequence of row (resp. column) sums amounts to
reordering the rows (resp. columns) themselves in the matrix,
which does not alter the columns (resp. rows) sums.
We can then assume that `r` and `s` are partitions
(see the corresponding class ``Partition``)
If `r^*` denote the conjugate of `r`, the Gale-Ryser theorem
asserts that a binary Matrix satisfying the constraints exists
if and only if `s\preceq r^*`, where `\preceq` denotes
the domination order on partitions.
EXAMPLES::
sage: from sage.combinat.integer_vector import is_gale_ryser
sage: is_gale_ryser([4,2,2],[3,3,1,1])
True
sage: is_gale_ryser([4,2,1,1],[3,3,1,1])
True
sage: is_gale_ryser([3,2,1,1],[3,3,1,1])
False
REMARK: In the literature, what we are calling a
Gale-Ryser sequence sometimes goes by the (rather
generic-sounding) term ''realizable sequence''.
"""
# The sequences only contan non-negative integers
if [x for x in r if x<0] or [x for x in s if x<0]:
return False
# builds the corresponding partitions, i.e.
# removes the 0 and sorts the sequences
from sage.combinat.partition import Partition
r2 = Partition(sorted([x for x in r if x>0], reverse=True))
s2 = Partition(sorted([x for x in s if x>0], reverse=True))
# If the two sequences only contained zeroes
if len(r2) == 0 and len(s2) == 0:
return True
rstar = Partition(r2).conjugate()
# same number of 1s domination
return len(rstar) <= len(s2) and sum(r2) == sum(s2) and rstar.dominates(s)