Generating Functions · Generating Functions
Lesson 3
Of course, it is not difficult to directly calculate this number. But what is important now is that this number is the coefficient of the monomial \(x^{10}\) in the polynomial \[(x^{2}+x^{3}+x^{6}+x^{7})(x^{3}+x^{4}+x^{5}+x^{8}) \ .\] The resulting polynomial will show the number of ways to obtain any sum (not just \(10\)): \[x^{5}+2x^{6}+2x^{7}+x^{8}+x^{9}+3x^{10}+3x^{11}+x^{12}+x^{14}+x^{15}\ .\] For example, there are two ways to obtain seven (\(2+5\) and \(3+4\)) and three ways to obtain eleven (\(3+8\), \(6+5\), \(7+4\)).
from sympy import expand
from sympy.abc import x
deg1, deg2 = (2, 3, 6, 7), (3, 4, 5, 8)
print(expand(sum(x ** d for d in deg1) * sum(x ** d for d in deg2)))x**15 + x**14 + x**12 + 3*x**11 + 3*x**10 + x**9 + x**8 + 2*x**7 + 2*x**6 + x**5