# Ticket #11411: trac_11411-q_analogues-review-fh.patch

File trac_11411-q_analogues-review-fh.patch, 4.4 KB (added by hivert, 9 years ago)
• ## sage/combinat/q_analogues.py

```# HG changeset patch
# User Florent Hivert <Florent.Hivert@univ-rouen.fr>
# Date 1307033169 -7200
# Node ID 6bba477a7ee07b745377a1e36550973e1af25642
# Parent  277fdbc7153644352144183714aca01787d69e53
#11411: Review patch for q-analogue fix.

diff --git a/sage/combinat/q_analogues.py b/sage/combinat/q_analogues.py```
 a from dyck_word import DyckWords def q_int(n, p=None): """ Returns the ``q``-analogue of the integer ``n``. If ``p`` is unspecified, then it defaults to using the generator ``q`` for a univariate polynomial ring over the integers. EXAMPLES:: sage: import sage.combinat.q_analogues as q_analogues sage: q_analogues.q_int(3) q^2 + q + 1 sage: p = ZZ['p'].0 sage: q_analogues.q_int(3,p) p^2 + p + 1 The ``q``-analogue of ``n`` is only defined for ``n`` a nonnegative integer (trac #11411):: sage: q_analogues.q_int(-2) Traceback (most recent call last): ... ValueError: Argument (-2) must be a nonnegative integer. """ if n in ZZ and n >= 0: if p == None: def q_int(n, p=None): def q_factorial(n, p=None): """ Returns the ``q``-analogue of the factorial ``n!``. If ``p`` is unspecified, then it defaults to using the generator ``q`` for a univariate polynomial ring over the integers. EXAMPLES:: sage: import sage.combinat.q_analogues as q_analogues sage: q_analogues.q_factorial(3) q^3 + 2*q^2 + 2*q + 1 sage: p = ZZ['p'].0 sage: q_analogues.q_factorial(3, p) p^3 + 2*p^2 + 2*p + 1 The ``q``-analogue of ``n!`` is only defined for ``n`` a nonnegative integer (trac #11411):: sage: q_analogues.q_factorial(-2) Traceback (most recent call last): ... ValueError: Argument (-2) must be a nonnegative integer. """ if n in ZZ and n >= 0: return prod([q_int(i, p) for i in range(1, n+1)]) def q_factorial(n, p=None): def q_binomial(n,k,p=None): """ Returns the ``q``-binomial coefficient. If ``p`` is unspecified, then it defaults to using the generator ``q`` for a univariate polynomial ring over the integers. EXAMPLES:: sage: import sage.combinat.q_analogues as q_analogues sage: q_analogues.q_binomial(4,2) q^4 + q^3 + 2*q^2 + q + 1 sage: p = ZZ['p'].0 sage: q_analogues.q_binomial(4,2,p) p^4 + p^3 + 2*p^2 + p + 1 The ``q``-analogue of ``binomial(n,k)`` is currently only defined for ``n`` a nonnegative integer, it is zero for negative k  (trac #11411):: sage: q_analogues.q_binomial(5, -1) 0 """ if n in ZZ and n >= 0 and k in ZZ: if 0 <= k and k <= n: k=min(k, n-k) return prod(q_int(j, p) for j in range(n-k+1, n+1)) / prod(q_int(j, p) for j in range(1, k+1)) else: return 0 if not (n in ZZ and k in ZZ): raise ValueError, "Argument (%s, %s) must be integers."%(n, k) if n < 0: raise NotImplementedError if 0 <= k and k <= n: k=min(k, n-k) return (prod(q_int(j, p) for j in range(n-k+1, n+1)) / prod(q_int(j, p) for j in range(1, k+1))) else: raise NotImplementedError return 0 def q_catalan_number(n,p=None): """ def q_catalan_number(n,p=None): sage: p = ZZ['p'].0 sage: q_analogues.q_catalan_number(4,p) p^12 + p^10 + p^9 + 2*p^8 + p^7 + 2*p^6 + p^5 + 2*p^4 + p^3 + p^2 + 1 The ``q``-Catalan number of index ``n`` is only defined for ``n`` a nonnegative integer (trac #11411):: sage: q_analogues.q_catalan_number(-2) Traceback (most recent call last): ... ValueError: Argument (-2) must be a nonnegative integer. """ if n in ZZ and n >= 0: return prod(q_int(j, p) for j in range(n+2, 2*n+1)) / prod(q_int(j, p) for j in range(2,n+1)) def q_catalan_number(n,p=None): def qt_catalan_number(n): """ Returns the ``q,t``-Catalan number of index ``n``. EXAMPLES:: sage: import sage.combinat.q_analogues as q_analogues sage: q_analogues.qt_catalan_number(1) 1