Exemplo n.º 1
0
def q_int(n, q=None):
    r"""
    Return the `q`-analog of the nonnegative integer `n`.

    The `q`-analog of the nonnegative integer `n` is given by

    .. MATH::

        [n]_q = \frac{q^n - q^{-n}}{q - q^{-1}}
        = q^{n-1} + q^{n-3} + \cdots + q^{-n+3} + q^{-n+1}.

    INPUT:

    - ``n`` -- the nonnegative integer `n` defined above
    - ``q`` -- (default: `q \in \ZZ[q, q^{-1}]`) the parameter `q`
      (should be invertible)

    If ``q`` is unspecified, then it defaults to using the generator `q`
    for a Laurent polynomial ring over the integers.

    .. NOTE::

        This is not the "usual" `q`-analog of `n` (or `q`-integer) but
        a variant useful for quantum groups. For the version used in
        combinatorics, see :mod:`sage.combinat.q_analogues`.

    EXAMPLES::

        sage: from sage.algebras.quantum_groups.q_numbers import q_int
        sage: q_int(2)
        q^-1 + q
        sage: q_int(3)
        q^-2 + 1 + q^2
        sage: q_int(5)
        q^-4 + q^-2 + 1 + q^2 + q^4
        sage: q_int(5, 1)
        5

    TESTS::

        sage: from sage.algebras.quantum_groups.q_numbers import q_int
        sage: q_int(1)
        1
        sage: q_int(0)
        0
    """
    if q is None:
        R = LaurentPolynomialRing(ZZ, 'q')
        q = R.gen()
    else:
        R = q.parent()
    if n == 0:
        return R.zero()
    return R.sum(q**(n - 2 * i - 1) for i in range(n))
Exemplo n.º 2
0
def q_int(n, q=None):
    r"""
    Return the `q`-analog of the nonnegative integer `n`.

    The `q`-analog of the nonnegative integer `n` is given by

    .. MATH::

        [n]_q = \frac{q^n - q^{-n}}{q - q^{-1}}
        = q^{n-1} + q^{n-3} + \cdots + q^{-n+3} + q^{-n+1}.

    INPUT:

    - ``n`` -- the nonnegative integer `n` defined above
    - ``q`` -- (default: `q \in \ZZ[q, q^{-1}]`) the parameter `q`
      (should be invertible)

    If ``q`` is unspecified, then it defaults to using the generator `q`
    for a Laurent polynomial ring over the integers.

    .. NOTE::

        This is not the "usual" `q`-analog of `n` (or `q`-integer) but
        a variant useful for quantum groups. For the version used in
        combinatorics, see :mod:`sage.combinat.q_analogues`.

    EXAMPLES::

        sage: from sage.algebras.quantum_groups.q_numbers import q_int
        sage: q_int(2)
        q^-1 + q
        sage: q_int(3)
        q^-2 + 1 + q^2
        sage: q_int(5)
        q^-4 + q^-2 + 1 + q^2 + q^4
        sage: q_int(5, 1)
        5

    TESTS::

        sage: from sage.algebras.quantum_groups.q_numbers import q_int
        sage: q_int(1)
        1
        sage: q_int(0)
        0
    """
    if q is None:
        R = LaurentPolynomialRing(ZZ, 'q')
        q = R.gen()
    else:
        R = q.parent()
    if n == 0:
        return R.zero()
    return R.sum(q**(n - 2 * i - 1) for i in range(n))