def to_noncrossing_set_partition(self): r""" Return the noncrossing set partition (on half as many elements) corresponding to the perfect matching if the perfect matching is noncrossing, and otherwise gives an error. OUTPUT: The realization of ``self`` as a noncrossing set partition. EXAMPLES:: sage: PerfectMatching([[1,3], [4,2]]).to_noncrossing_set_partition() Traceback (most recent call last): ... ValueError: matching must be non-crossing sage: PerfectMatching([[1,4], [3,2]]).to_noncrossing_set_partition() {{1, 2}} sage: PerfectMatching([]).to_noncrossing_set_partition() {} """ if not self.is_noncrossing(): raise ValueError("matching must be non-crossing") else: perm = self.to_permutation() perm2 = Permutation( [perm[2 * i] // 2 for i in range(len(perm) // 2)]) return SetPartition(perm2.cycle_tuples())
def __getitem__(self, i): """ Return the basis element indexed by ``i``. INPUT: - ``i`` -- a set partition or a list of list of integers EXAMPLES:: sage: w = SymmetricFunctionsNonCommutingVariables(QQ).dual().w() sage: w[[1], [2,3]] w{{1}, {2, 3}} sage: w[{1}, (2,3)] w{{1}, {2, 3}} sage: w[[]] w{} """ if isinstance(i, SetPartition): return self.monomial(i) if i == []: return self.one() if not isinstance(i, tuple): i = (i, ) return self.monomial(SetPartition(i))
def standardization(self): """ Return the standardization of ``self``. See :meth:`SetPartition.standardization` for details. EXAMPLES:: sage: n = PerfectMatching([('c','b'),('d','f'),('e','a')]) sage: n.standardization() [(1, 5), (2, 3), (4, 6)] """ P = PerfectMatchings(2 * len(self)) return P(SetPartition.standardization(self))
def standardization(self): """ Return the standardization of ``self``. See :meth:`SetPartition.standardization` for details. EXAMPLES:: sage: n = PerfectMatching([('c','b'),('d','f'),('e','a')]) sage: n.standardization() [(1, 5), (2, 3), (4, 6)] """ P = PerfectMatchings(2*len(self)) return P(SetPartition.standardization(self))
def one_basis(self): r""" Return the index of the basis element containing `1`. OUTPUT: - The empty set partition EXAMPLES:: sage: m = SymmetricFunctionsNonCommutingVariables(QQ).m() sage: m.one_basis() {} sage: w = SymmetricFunctionsNonCommutingVariables(QQ).dual().w() sage: w.one_basis() {} """ return SetPartition([])
def _element_constructor_(self, x): """ Construct an element of ``self``. INPUT: - ``x`` -- a set partition or list of lists of integers EXAMPLES:: sage: m = SymmetricFunctionsNonCommutingVariables(QQ).m() sage: m([[1,3],[2]]) m{{1, 3}, {2}} sage: m(SetPartition([[1,3],[2]])) m{{1, 3}, {2}} """ if isinstance(x, (list, tuple)): x = SetPartition(x) return super(NCSymBasis_abstract, self)._element_constructor_(x)
def decomposition(self): """ Find the decomposition of the matroid as a direct sum of indecomposable matroids. Return a partition of the groundset. Uses the algorithm of [PP19, Section 7]. """ B = self.basis() new_groundset = list(B) + list(self.groundset().difference(B)) # construct matrix with permuted columns columns = [vector(self._A[:,self._groundset_to_index[e]]) for e in new_groundset] A = matrix(ZZ, columns).transpose().echelon_form() uf = DisjointSet(self.groundset()) for i in xrange(A.nrows()): for j in xrange(i+1, A.ncols()): if A[i,j] != 0: uf.union(new_groundset[i], new_groundset[j]) return SetPartition(uf)