Expansions of a bivariate rational function.
Requirements: None
# Define the multivariate power series ring
R = PowerSeriesRing(QQ,2,'x,y')
(x,y) = R.gens()
# Compute initial 10 terms in the power series expansion under consideration
ser = 1/(1-x-y).O(10)
ser
1 + x + y + x^2 + 2*x*y + y^2 + x^3 + 3*x^2*y + 3*x*y^2 + y^3 + x^4 + 4*x^3*y + 6*x^2*y^2 + 4*x*y^3 + y^4 + x^5 + 5*x^4*y + 10*x^3*y^2 + 10*x^2*y^3 + 5*x*y^4 + y^5 + x^6 + 6*x^5*y + 15*x^4*y^2 + 20*x^3*y^3 + 15*x^2*y^4 + 6*x*y^5 + y^6 + x^7 + 7*x^6*y + 21*x^5*y^2 + 35*x^4*y^3 + 35*x^3*y^4 + 21*x^2*y^5 + 7*x*y^6 + y^7 + x^8 + 8*x^7*y + 28*x^6*y^2 + 56*x^5*y^3 + 70*x^4*y^4 + 56*x^3*y^5 + 28*x^2*y^6 + 8*x*y^7 + y^8 + x^9 + 9*x^8*y + 36*x^7*y^2 + 84*x^6*y^3 + 126*x^5*y^4 + 126*x^4*y^5 + 84*x^3*y^6 + 36*x^2*y^7 + 9*x*y^8 + y^9 + O(x, y)^10
# Verify coefficients are given by binomial coefficients
add([binomial(i+j,i)*x^i*y^j for i in range(10) for j in range(10-i)]) - ser
0 + O(x, y)^10
# The diagonal terms are the central binomial coefficients
coeffs = (1/(1-x-y).O(20)).coefficients()
print([coeffs.get(x^i*y^i,0) for i in range(10)])
print([binomial(2*n,n) for n in range(10)])
[1, 2, 6, 20, 70, 252, 924, 3432, 12870, 48620] [1, 2, 6, 20, 70, 252, 924, 3432, 12870, 48620]
# Multivariate series expansions can also be computed using the "taylor" command
var('a,b')
taylor(1/(1-a-b),(a,0),(b,0),10)
a^10 + 10*a^9*b + 45*a^8*b^2 + 120*a^7*b^3 + 210*a^6*b^4 + 252*a^5*b^5 + 210*a^4*b^6 + 120*a^3*b^7 + 45*a^2*b^8 + 10*a*b^9 + b^10 + a^9 + 9*a^8*b + 36*a^7*b^2 + 84*a^6*b^3 + 126*a^5*b^4 + 126*a^4*b^5 + 84*a^3*b^6 + 36*a^2*b^7 + 9*a*b^8 + b^9 + a^8 + 8*a^7*b + 28*a^6*b^2 + 56*a^5*b^3 + 70*a^4*b^4 + 56*a^3*b^5 + 28*a^2*b^6 + 8*a*b^7 + b^8 + a^7 + 7*a^6*b + 21*a^5*b^2 + 35*a^4*b^3 + 35*a^3*b^4 + 21*a^2*b^5 + 7*a*b^6 + b^7 + a^6 + 6*a^5*b + 15*a^4*b^2 + 20*a^3*b^3 + 15*a^2*b^4 + 6*a*b^5 + b^6 + a^5 + 5*a^4*b + 10*a^3*b^2 + 10*a^2*b^3 + 5*a*b^4 + b^5 + a^4 + 4*a^3*b + 6*a^2*b^2 + 4*a*b^3 + b^4 + a^3 + 3*a^2*b + 3*a*b^2 + b^3 + a^2 + 2*a*b + b^2 + a + b + 1
# Perhaps the easiest way to get the diagonal from a taylor expansion is to cast to a multivariate polynomial
# As polynomial coefficients can be accessed the same as lists
ser2 = taylor(1/(1-a-b),(a,0),(b,0),20)
[QQ[a,b](ser2)[k,k] for k in range(10)]
[1, 2, 6, 20, 70, 252, 924, 3432, 12870, 48620]