Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
fix parent of q_catalan numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
fchapoton committed Mar 17, 2020
1 parent 6db1a26 commit 3f62bbb
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions src/sage/combinat/q_analogues.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def q_int(n, q=None):

def q_factorial(n, q=None):
"""
Returns the `q`-analogue of the factorial `n!`.
Return the `q`-analogue of the factorial `n!`.
If `q` is unspecified, then it defaults to using the generator `q` for
a univariate polynomial ring over the integers.
Expand Down Expand Up @@ -356,8 +356,8 @@ def q_binomial(n, k, q=None, algorithm='auto'):
return q_binomial(n, k)(q)
if algorithm == 'cyclotomic':
from sage.rings.polynomial.cyclotomic import cyclotomic_value
return prod(cyclotomic_value(d,q)
for d in range(2,n+1)
return prod(cyclotomic_value(d, q)
for d in range(2, n + 1)
if (n//d) != (k//d) + ((n-k)//d))
else:
raise ValueError("unknown algorithm {!r}".format(algorithm))
Expand Down Expand Up @@ -433,6 +433,7 @@ def q_multinomial(seq, q=None, binomial_algorithm='auto'):
binomials.append(q_binomial(partial_sum, elem, q=q, algorithm=binomial_algorithm))
return prod(binomials)


gaussian_multinomial = q_multinomial


Expand Down Expand Up @@ -461,23 +462,27 @@ def q_catalan_number(n, q=None):
sage: q_catalan_number(-2)
Traceback (most recent call last):
...
ValueError: Argument (-2) must be a nonnegative integer.
ValueError: argument (-2) must be a nonnegative integer
TESTS::
sage: q_catalan_number(3).parent()
Univariate Polynomial Ring in q over Integer Ring
sage: q_catalan_number(0).parent()
Univariate Polynomial Ring in q over Integer Ring
"""
if n in ZZ and n >= 0:
return (prod(q_int(j, q) for j in range(n + 2, 2 * n + 1)) //
prod(q_int(j, q) for j in range(2, n + 1)))
else:
raise ValueError("Argument (%s) must be a nonnegative integer." % n)
if n in ZZ:
if n in {0, 1}:
return q_int(1, q)
elif n >= 2:
return (prod(q_int(j, q) for j in range(n + 2, 2 * n + 1)) //
prod(q_int(j, q) for j in range(2, n + 1)))
raise ValueError("argument (%s) must be a nonnegative integer" % n)


def qt_catalan_number(n):
"""
Returns the `q,t`-Catalan number of index `n`.
Return the `q,t`-Catalan number of index `n`.
EXAMPLES::
Expand All @@ -500,7 +505,7 @@ def qt_catalan_number(n):
ValueError: Argument (-2) must be a nonnegative integer.
"""
if n in ZZ and n >= 0:
ZZqt = ZZ['q','t']
ZZqt = ZZ['q', 't']
d = {}
for dw in DyckWords(n):
tup = (dw.area(), dw.bounce())
Expand Down Expand Up @@ -577,7 +582,7 @@ def q_pochhammer(n, a, q=None):
R = parent(q)
one = R(1)
if n < 0:
return R.prod(one / (one - a/q**-k) for k in range(1,-n+1))
return R.prod(one / (one - a/q**-k) for k in range(1, -n+1))
return R.prod((one - a*q**k) for k in range(n))


Expand Down Expand Up @@ -883,6 +888,7 @@ def q_stirling_number1(n, k, q=None):
return (q_stirling_number1(n - 1, k - 1, q=q) +
q_int(n - 1, q=q) * q_stirling_number1(n - 1, k, q=q))


@cached_function
def q_stirling_number2(n, k, q=None):
r"""
Expand Down Expand Up @@ -932,7 +938,6 @@ def q_stirling_number2(n, k, q=None):
REFERENCES:
- [Mil1978]_
"""
if q is None:
q = ZZ['q'].gen()
Expand Down

0 comments on commit 3f62bbb

Please sign in to comment.