Ask Your Question

Revision history [back]

I consider this as a bug, bell_polynomial(n,k) should always be an element of a polynomial ring, see the OUTPUT field of the doc. I am writing a patch for that. Thanks for reporting.

The cause of your problem is that bell_polynomial(0,0) does not return 1 as a polynomial, but as a rational number.

sage: bell_polynomial(0,0)
1
sage: bell_polynomial(0,0).parent()
Rational Field

I consider this as a bug, bug : bell_polynomial(n,k) should always be an element of a polynomial ring, see the doc claims explicitely that the output should be "a polynomial in OUTPUTn-k+1 field of the doc. I am writing a patch for that. variables over \QQ". Thanks for reporting.reporting. This is now trac ticket 18338.

With the patch applied, you get directly:

sage: bell_polynomial(0,0)
1
sage: bell_polynomial(0,0).parent()
Univariate Polynomial Ring in x_1 over Rational Field

sage: for n in (0..4):
....:     print [bell_polynomial(n,k) for k in (0..n)]
[1]
[0, x_1]
[0, x_2, x_1^2]
[0, x_3, 3*x_1*x_2, x_1^3]
[0, x_4, 3*x_2^2 + 4*x_1*x_3, 6*x_1^2*x_2, x_1^4]

The cause of your problem is that bell_polynomial(0,0) does not return 1 as a polynomial, but as a rational number.

sage: bell_polynomial(0,0)
1
sage: bell_polynomial(0,0).parent()
Rational Field

I consider this as a bug : bell_polynomial(n,k) should always be an element of a polynomial ring, the doc claims explicitely that the output should be "a polynomial in n-k+1 variables over \QQ". Thanks for reporting. This is now trac ticket 18338. (needs review).

With the patch applied, you get directly:

sage: bell_polynomial(0,0)
1
sage: bell_polynomial(0,0).parent()
Univariate Polynomial Ring in x_1 over Rational Field

sage: for n in (0..4):
....:     print [bell_polynomial(n,k) for k in (0..n)]
[1]
[0, x_1]
[0, x_2, x_1^2]
[0, x_3, 3*x_1*x_2, x_1^3]
[0, x_4, 3*x_2^2 + 4*x_1*x_3, 6*x_1^2*x_2, x_1^4]

The cause of your problem is that bell_polynomial(0,0) does not return 1 as a polynomial, but as a rational number.

sage: bell_polynomial(0,0)
1
sage: bell_polynomial(0,0).parent()
Rational Field

I consider this as a bug : bell_polynomial(n,k) should always be an element of a polynomial ring, the doc claims explicitely that the output should be "a polynomial in n-k+1 variables over \QQ". Thanks for reporting. This is now trac ticket 18338 (needs review).

With the patch applied, you get directly:

sage: bell_polynomial(0,0)
1
sage: bell_polynomial(0,0).parent()
Univariate Polynomial Ring in x_1 over Rational Field

sage: for n in (0..4):
....:     print [bell_polynomial(n,k) for k in (0..n)]
[1]
[0, x_1]
[0, x_2, x_1^2]
[0, x_3, 3*x_1*x_2, x_1^3]
[0, x_4, 3*x_2^2 + 4*x_1*x_3, 6*x_1^2*x_2, x_1^4]


sage: sage: for n in (0..4):
....:     print [bell_polynomial(n,k).coefficients() for k in (0..n)]
[[1]]
[[], [1]]
[[], [1], [1]]
[[], [1], [3], [1]]
[[], [1], [3, 4], [6], [1]]