Re: Multiplying Polynomials
- To: mathgroup at smc.vnet.net
- Subject: [mg117949] Re: Multiplying Polynomials
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Tue, 5 Apr 2011 06:44:29 -0400 (EDT)
The first argument to FindGeneratingFunction is the list of the coefficients, not a list of the terms. n = 4; t = a^Range[0, n] {1, a, a^2, a^3, a^4} gf = FindGeneratingFunction[t, x] 1/(1 - a*x) t == CoefficientList[Series[gf, {x, 0, n}], x] True m = RandomInteger[{2, 6}] 3 gfm = FindGeneratingFunction[t, x^m] 1/(1 - a*x^3) t == CoefficientList[Series[gfm, {x, 0, m*n}], x^m] True Bob Hanlon ---- Dana DeLouis <dana.del at gmail.com> wrote: ============= > ...expand[(1+ax+a^2x^2+...)* Hi. Not sure, but it seems your question has revealed =93another=94 bug in Math 8.0. Your use of ... in the equation above indicates you may want to use more terms in the future. I will assume the sequence is the following. It seems to agree with your solution up to Poly. of 2, and the letters a-c. t={1,a x,a^2 x^2,a^3 x^3,a^4 x^4}; FindGeneratingFunction[t,x] 1/(1-a x^2) The above is incorrect! Another bug in 8.0? Let's See: Series[1/(1-a x^2),{x,0,6}]//Normal 1+a x^2+a^2 x^4+a^3 x^6 By inspection, the correct solution should be (note: x vs x^2) Series[1/(1-a x),{x,0,4}]//Normal 1+a x+a^2 x^2+a^3 x^3+a^4 x^4 I'll make a simple function: gf[letter_,n_]:=Series[1/(1-letter* x),{x,0,n}]//Normal Quick test: gf[a,5] 1+a x+a^2 x^2+a^3 x^3+a^4 x^4+a^5 x^5 I'll test your solution up to x^2, and the letters a-c: v=gf[#,2]&/@(CharacterRange["a","c"]//ToExpression) {1+a x+a^2 x^2,1+b x+b^2 x^2,1+c x+c^2 x^2} Fold[Expand[#1*#2]&,First[v],Rest[v]]; << I get the same solution here as what you posted. >> Now, for x^2, and letters a-d. v=gf[#,2]&/@(CharacterRange["a","d"]//ToExpression) {1+a x+a^2 x^2,1+b x+b^2 x^2,1+c x+c^2 x^2,1+d x+d^2 x^2} Fold[Expand[#1*#2]&,First[v],Rest[v]]; << answer here >> I'm not sure if the following would help in your final solution: Let's redo the x^2 and letters a-d: v=gf[#,2]&/@(CharacterRange["a","d"]//ToExpression); z=Fold[Expand[#1*#2]&,First[v],Rest[v]]; Let's collect the terms by x, and look at x^3. List@@Collect[z,x]; << not shown >> List@@Coefficient[z,x,3] {a^2 b,a b^2,a^2 c,a b c,b^2 c,a c^2,b c^2,a^2 d,a b d,b^2 d,a c d,b c d,c^2 d,a d^2,b d^2,c d^2} There are 16 terms for x^3. Notice that the sum of the power terms equals 3 to match the x^3 term. (same for each other x term) These 16 could be generated by: (ie 3 for x^3, 4 for a-d, and 2 for the max initial term x^2 ) Permutations/@IntegerPartitions[3,{4},Range[0,2]] = {{{2,1,0,0},{2,0,1,0},{2,0,0,1},{1,2,0,0},{1,0,2,0},{1,0,0,2},{0,2,1,0},{0,2,0,1},{0,1,2,0},{0,1,0,2},{0,0,2,1},{0,0,1,2}},{{1,1,1,0},{1,1,0,1},{1,0,1,1},{0,1,1,1}}} What this says is that the x^3 term has a^2 b, a^2 c, ...etc The last term being b*c*d. As a side note, I wish the Text-Copy keyboard shortcut sequence (Command+Shift+C) would put in the implied Multiplication symbol. I seem to waste time because the output doesn't look right as text. 1+a x+a^2 x^2+a^3 x^3+a^4 x^4 I wish it did... 1+a*x+a^2*x^2+a^3*x^3+a^4*x^4 = = = = = = = = = HTH : >) Dana DeLouis Mac, Math 8.0 On Apr 2, 3:51 am, TBone <TB... at yahoo.com> wrote: > This is very simple and I freely confess my ingnorance. > > I'm trying to set up a generating function to count some letters of the > alphabet. Specifically, I need to multiply two polynomials in the > variable x, do some surgery on the result, and continue with another > letter. > > Here is my problem. > > I start with: > > expand[(1+ax+a^2x^2+...)*(1+bx+b^2x^2+...)] > > and continue with: > > expand[(1+ax+bx+abx^2+...)*(1+cx+c^2x^2+...)] > > Howerver, it chokes on the following: > > expand[(1 + a x + b x + c x + a^2 x^2 + a b x^2 + b^2 x^2 + a c x^2 + b > c x^2 + > c^2 x^2 + a^2 b x^3 + a b^2 x^3 + a^2 c x^3 + a b c x^3 + b^2 c x^3 + > a c^2 x^3 + b c^2 x^3 + a^2 b^2 x^4 + a^2 b c x^4 + a b^2 c x^4 + > a^2 c^2 x^4 + a b c^2 x^4 + b^2 c^2 x^4 + a^2 b^2 c x^5 + a^2 b c^2 x^5 + > a b^2 c^2 x^5 + a^2 b^2 c^2 x^6)*(1 + dx + d^2 x^2)] > > What gives? > > TIA!! > > --TB