def IntegerPartitions(n): """ Returns the poset of integer partitions on the integer ``n``. A partition of a positive integer `n` is a non-increasing list of positive integers that sum to `n`. If `p` and `q` are integer partitions of `n`, then `p` covers `q` if and only if `q` is obtained from `p` by joining two parts of `p` (and sorting, if necessary). EXAMPLES:: sage: P = Posets.IntegerPartitions(7); P Finite poset containing 15 elements sage: len(P.cover_relations()) 28 """ def lower_covers(partition): r""" Nested function for computing the lower covers of elements in the poset of integer partitions. """ lc = [] for i in range(0, len(partition) - 1): for j in range(i + 1, len(partition)): new_partition = partition[:] del new_partition[j] del new_partition[i] new_partition.append(partition[i] + partition[j]) new_partition.sort(reverse=True) tup = tuple(new_partition) if tup not in lc: lc.append(tup) return lc from sage.combinat.partition import partitions_list H = DiGraph( dict([[tuple(p), lower_covers(p)] for p in partitions_list(n)])) return Poset(H.reverse())
def IntegerPartitions(n): """ Returns the poset of integer partitions on the integer ``n``. A partition of a positive integer `n` is a non-increasing list of positive integers that sum to `n`. If `p` and `q` are integer partitions of `n`, then `p` covers `q` if and only if `q` is obtained from `p` by joining two parts of `p` (and sorting, if necessary). EXAMPLES:: sage: P = Posets.IntegerPartitions(7); P Finite poset containing 15 elements sage: len(P.cover_relations()) 28 """ def lower_covers(partition): r""" Nested function for computing the lower covers of elements in the poset of integer partitions. """ lc = [] for i in range(0,len(partition)-1): for j in range(i+1,len(partition)): new_partition = partition[:] del new_partition[j] del new_partition[i] new_partition.append(partition[i]+partition[j]) new_partition.sort(reverse=True) tup = tuple(new_partition) if tup not in lc: lc.append(tup) return lc from sage.combinat.partition import partitions_list H = DiGraph(dict([[tuple(p),lower_covers(p)] for p in partitions_list(n)])) return Poset(H.reverse())
def RestrictedIntegerPartitions(n): """ Returns the poset of integer partitions on the integer `n` ordered by restricted refinement. That is, if `p` and `q` are integer partitions of `n`, then `p` covers `q` if and only if `q` is obtained from `p` by joining two distinct parts of `p` (and sorting, if necessary). EXAMPLES:: sage: P = Posets.RestrictedIntegerPartitions(7); P Finite poset containing 15 elements sage: len(P.cover_relations()) 17 """ def lower_covers(partition): r""" Nested function for computing the lower covers of elements in the restricted poset of integer partitions. """ lc = [] for i in range(0,len(partition)-1): for j in range(i+1,len(partition)): if partition[i] != partition[j]: new_partition = partition[:] del new_partition[j] del new_partition[i] new_partition.append(partition[i]+partition[j]) new_partition.sort(reverse=True) tup = tuple(new_partition) if tup not in lc: lc.append(tup) return lc from sage.combinat.partition import Partitions H = DiGraph(dict([[tuple(p),lower_covers(p)] for p in Partitions(n)])) return Poset(H.reverse())
def RestrictedIntegerPartitions(n): """ Returns the poset of integer partitions on the integer `n` ordered by restricted refinement. That is, if `p` and `q` are integer partitions of `n`, then `p` covers `q` if and only if `q` is obtained from `p` by joining two distinct parts of `p` (and sorting, if necessary). EXAMPLES:: sage: P = Posets.RestrictedIntegerPartitions(7); P Finite poset containing 15 elements sage: len(P.cover_relations()) 17 """ def lower_covers(partition): r""" Nested function for computing the lower covers of elements in the restricted poset of integer partitions. """ lc = [] for i in range(0, len(partition) - 1): for j in range(i + 1, len(partition)): if partition[i] != partition[j]: new_partition = partition[:] del new_partition[j] del new_partition[i] new_partition.append(partition[i] + partition[j]) new_partition.sort(reverse=True) tup = tuple(new_partition) if tup not in lc: lc.append(tup) return lc from sage.combinat.partition import Partitions H = DiGraph(dict([[tuple(p), lower_covers(p)] for p in Partitions(n)])) return Poset(H.reverse())