Exemple #1
0
    def __init__(self, R, elements):
        """
        Initialize ``self``.

        EXAMPLES::

            sage: R.<x,y,z> = QQ[]
            sage: K = KoszulComplex(R, [x,y])
            sage: TestSuite(K).run()
        """
        # Generate the differentials
        self._elements = elements
        n = len(elements)
        I = range(n)
        diff = {}
        zero = R.zero()
        for i in I:
            M = matrix(R, binomial(n,i), binomial(n,i+1), zero)
            j = 0
            for comb in itertools.combinations(I, i+1):
                for k,val in enumerate(comb):
                    r = rank(comb[:k] + comb[k+1:], n, False)
                    M[r,j] = (-1)**k * elements[val]
                j += 1
            M.set_immutable()
            diff[i+1] = M
        diff[0] = matrix(R, 0, 1, zero)
        diff[0].set_immutable()
        diff[n+1] = matrix(R, 1, 0, zero)
        diff[n+1].set_immutable()
        ChainComplex_class.__init__(self, ZZ, ZZ(-1), R, diff)
Exemple #2
0
    def __init__(self, R, elements):
        """
        Initialize ``self``.

        EXAMPLES::

            sage: R.<x,y,z> = QQ[]
            sage: K = KoszulComplex(R, [x,y])
            sage: TestSuite(K).run()
        """
        # Generate the differentials
        self._elements = elements
        n = len(elements)
        I = list(range(n))
        diff = {}
        zero = R.zero()
        for i in I:
            M = matrix(R, binomial(n, i), binomial(n, i + 1), zero)
            j = 0
            for comb in itertools.combinations(I, i + 1):
                for k, val in enumerate(comb):
                    r = rank(comb[:k] + comb[k + 1:], n, False)
                    M[r, j] = (-1)**k * elements[val]
                j += 1
            M.set_immutable()
            diff[i + 1] = M
        diff[0] = matrix(R, 0, 1, zero)
        diff[0].set_immutable()
        diff[n + 1] = matrix(R, 1, 0, zero)
        diff[n + 1].set_immutable()
        ChainComplex_class.__init__(self, ZZ, ZZ(-1), R, diff)
Exemple #3
0
def rank(comb, n, check=True):
    """
    Return the rank of ``comb`` in the subsets of ``range(n)`` of size ``k``
    where ``k`` is the length of ``comb``.

    The algorithm used is based on combinadics and James McCaffrey's
    MSDN article. See: :wikipedia:`Combinadic`.

    EXAMPLES::

        sage: import sage.combinat.choose_nk as choose_nk
        sage: choose_nk.rank((), 3)
        doctest:...: DeprecationWarning: choose_nk.rank is deprecated and will be removed. Use combination.rank instead
        See http://trac.sagemath.org/18674 for details.
        0
        sage: choose_nk.rank((0,), 3)
        0
        sage: choose_nk.rank((1,), 3)
        1
        sage: choose_nk.rank((2,), 3)
        2
        sage: choose_nk.rank((0,1), 3)
        0
        sage: choose_nk.rank((0,2), 3)
        1
        sage: choose_nk.rank((1,2), 3)
        2
        sage: choose_nk.rank((0,1,2), 3)
        0

        sage: choose_nk.rank((0,1,2,3), 3)
        Traceback (most recent call last):
        ...
        ValueError: len(comb) must be <= n
        sage: choose_nk.rank((0,0), 2)
        Traceback (most recent call last):
        ...
        ValueError: comb must be a subword of (0,1,...,n)

        sage: choose_nk.rank([1,2], 3)
        2
        sage: choose_nk.rank([0,1,2], 3)
        0
    """
    from sage.misc.superseded import deprecation
    deprecation(
        18674,
        "choose_nk.rank is deprecated and will be removed. Use combination.rank instead"
    )
    return combination.rank(comb, n, check)
Exemple #4
0
def rank(comb, n, check=True):
    """
    Return the rank of ``comb`` in the subsets of ``range(n)`` of size ``k``
    where ``k`` is the length of ``comb``.

    The algorithm used is based on combinadics and James McCaffrey's
    MSDN article. See :wikipedia:`Combinadic`.

    EXAMPLES::

        sage: import sage.combinat.choose_nk as choose_nk
        sage: choose_nk.rank((), 3)
        doctest:...: DeprecationWarning: choose_nk.rank is deprecated and will be removed. Use combination.rank instead
        See http://trac.sagemath.org/18674 for details.
        0
        sage: choose_nk.rank((0,), 3)
        0
        sage: choose_nk.rank((1,), 3)
        1
        sage: choose_nk.rank((2,), 3)
        2
        sage: choose_nk.rank((0,1), 3)
        0
        sage: choose_nk.rank((0,2), 3)
        1
        sage: choose_nk.rank((1,2), 3)
        2
        sage: choose_nk.rank((0,1,2), 3)
        0

        sage: choose_nk.rank((0,1,2,3), 3)
        Traceback (most recent call last):
        ...
        ValueError: len(comb) must be <= n
        sage: choose_nk.rank((0,0), 2)
        Traceback (most recent call last):
        ...
        ValueError: comb must be a subword of (0,1,...,n)

        sage: choose_nk.rank([1,2], 3)
        2
        sage: choose_nk.rank([0,1,2], 3)
        0
    """
    from sage.misc.superseded import deprecation
    deprecation(18674, "choose_nk.rank is deprecated and will be removed. Use combination.rank instead")
    return combination.rank(comb, n, check)