extract coefficients from products and sums of descending products
I need to extract coefficients of n from some powers, products and sums of descending products and their reciprocals. The first 5 terms (in x) of the descending product (x)y are xy(1−y(y−1)2x+y(y−1)(y−2)(3y−1)24x2−y2(y−1)2(y−2)(y−3)48x3+y(y−1)(y−2)(y−3)(y−4)(15y3−30y2+5y+2)5760x4) and the first 5 terms of its reciprocal are x−y(1+y(y−1)2x+y(y−1)(y+1)(3y−2)24x2+y2(y−1)2(y+1)(y+2)48x3+y(y−1)(y+1)(y+2)(y+3)(15y3−15y2−10y+8)5760x4)
I need to extract the coefficients of various powers of n in expressions like
(l(v−1)−1)(v−1)l(l)t(n−1)t+1−((l(v−1)−1)(v−1)l(l)t(n−1)t+1)2+n(v−1)l(l)2t(l(v−1)−1)2(l(v−1)−2)(n)2t+3 where l=n/v and n, t and v are symbolic variables.
To encapsulate these descending products and their powers I wrote
def desc_prod(x,y):
t0 = 1
t1 = - y*(y-1)/(2*x)
t2 = (y*(y-1)*(y-2)*(3*y-1))/(24*x^2)
t3 = -(y^2*(y-1)^2*(y-2)*(y-3))/(48*x^3)
t4 = y*(y-1)*(y-2)*(y-3)*(y-4)*(15*y^3-30*y^2 + 5*y + 2)/(5760*x^4)
return (x^y)*(t0 + t1 + t2 + t3 + t4 )
def desc_prod_recip(x,y):
t0 = 1
t1 = y*(y-1)/(2*x)
t2 = (y*(y+1)*(y-1)*(3*y-2))/(24*x^2)
t3 = (y^2*(y-1)^2*(y+1)*(y+2))/(48*x^3)
t4 = y*(y-1)*(y+1)*(y+2)*(y+3)*(15*y^3-15*y^2-10*y+8)/(5760*x^4)
return (x^(-y))*(t0 + t1 + t2 + t3 + t4)
def desc_prod_power(x,y,e):
t0 = 1
t1 = - y*(y-1)/(2*x)
t2 = (y*(y-1)*(y-2)*(3*y-1))/(24*x^2)
t3 = -(y^2*(y-1)^2*(y-2)*(y-3))/(48*x^3)
t4 = y*(y-1)*(y-2)*(y-3)*(y-4)*(15*y^3-30*y^2 + 5*y + 2)/(5760*x^4)
return (x^(y*e))*(1 + multinomial(e-1,1)*t1 + multinomial(e-2,2)*t1^2 + multinomial(e-1,1)*t2 + multinomial(e-3,3)*t1^3 + multinomial(e-2,1,1)*t1*t2 + multinomial(e-4,4)*t1^4 + multinomial(e-2,2)*t2^2 + multinomial(e-3,2,1)*t1^2*t2 + multinomial(e-2,1,1)*t1*t3 + multinomial(e-1,1)*t4 )
def desc_prod_recip_power(x,y,e):
t0 = 1
t1 = y*(y-1)/(2*x)
t2 = (y*(y+1)*(y-1)*(3*y-2))/(24*x^2)
t3 = (y^2*(y-1)^2*(y+1)*(y+2))/(48*x^3)
t4 = y*(y-1)*(y+1)*(y+2)*(y+3)*(15*y^3-15*y^2-10*y+8)/(5760*x^4)
return (x^(-y*e))*(1 + multinomial(e-1,1)*t1 + multinomial(e-2,2)*t1^2 + multinomial(e-1,1)*t2 + multinomial(e-3,3)*t1^3 + multinomial(e-2,1,1)*t1*t2 + multinomial(e-4,4)*t1^4 + multinomial(e-2,2)*t2^2 + multinomial(e-3,2,1)*t1^2*t2 + multinomial(e-2,1,1)*t1*t3 + multinomial(e-1,1)*t4 )
but sagemath does not correctly compute the coefficients in n. In an attempt to figure this out I asked a question here about computing coefficients of n correctly and you can see there a very simple instance of sagemath failing to compute the coefficient. In my question I tried to give the simplest situation, where I do not have powers, products nor sums of my descnding products and their reciprocals, but just enough to showcase the behaviour of sage that is getting me stuck. In his answer @dan_fulea suggests that I need to approach my problem differently. Can anyone please give me some advice about the best way to compute the coefficients of any given power of n in expressions like mine.