Ticket #11411: correction_q_analogues_fc.patch

File correction_q_analogues_fc.patch, 1.1 KB (added by chapoton, 9 years ago)
  • sage/combinat/q_analogues.py

    # HG changeset patch
    # User Frederic Chapoton <chapoton at math.univ-lyon1.fr>
    # Date 1306856555 -7200
    # Node ID 9cc67cb6600742965ec00b92094378ab2a0d4b3d
    # Parent  85fbbf73ba511c55be136de163b63a8aa1868a4e
    #11411 This patch changes the behavior of q-factorials and q-binomial coefficients
    
    diff --git a/sage/combinat/q_analogues.py b/sage/combinat/q_analogues.py
    a b def q_factorial(n, p=None): 
    5757        sage: q_analogues.q_factorial(3, p)
    5858        p^3 + 2*p^2 + 2*p + 1
    5959    """
    60     return prod([q_int(i,p) for i in range(1, n+1)])
     60    if n>=0:
     61        return prod([q_int(i,p) for i in range(1, n+1)])
     62    else:
     63        raise ValueError, "argument (%s) must be nonnegative" %n
    6164
    6265def q_binomial(n,k,p=None):
    6366    """
    def q_binomial(n,k,p=None): 
    7578        sage: q_analogues.q_binomial(4,2,p)
    7679        p^4 + p^3 + 2*p^2 + p + 1
    7780    """
    78 
    79     return q_factorial(n,p)/(q_factorial(k,p)*q_factorial(n-k,p))
    80 
     81    if 0<=k and k<=n:
     82        return q_factorial(n,p)/(q_factorial(k,p)*q_factorial(n-k,p))
     83    else:
     84        return 0
    8185
    8286def qt_catalan_number(n):
    8387    """