2976301

https://math.stackexchange.com/questions/2976301/combinatorial-problem-using-generating-functions

Every day we buy exactly one of the following products: pretzel (1 euro), candy (2 euro), icecream (2 euros). What is the number of possible ways of spending all the money (the order of the bought products counts)?

If $$k$$ is the number of days and $$n$$ the number of euros, the number of possibilities is :

$$\binom {k}{n-k} 2^{n-k}$$

The generating function for one day is:

$$oneday = pde + cde^2 + ide^2$$

where $$d$$ is a counter for the number of days, $$e$$ for the number of euros, and $$p$$, $$c$$, $$i$$ for candies number.

k days will be described by :

$$oneday^k = (pe + ce^2 + ie^2)^k$$

( I dropped d as redundant)

Examining the computed numbers for small $$k$$ and $$n$$'s, the pattern occurs.

In $$k$$ days we can spend $$k...2k$$ euros. If we spends $$k+l$$ this is because in some $$l$$ days we buy $$l$$ expensive candies. These candies may be one of two types.

The sum for fixed $$k$$ is $$3^k$$.

The sum for fixed $$n$$ is "Jacobsthal number" : see https://oeis.org/A001045.

$$0, 1, 1, 3, 5, 11, 21, 43, 85, 171...$$

The recurrence $$a_n = a_{n-1} + 2a_{n-2}$$ is nice and simple to explain.

Exponential generating functions are not useful for identical objects, but for distinct ones.

Maybe I should explain more. A generating function is an expression that encodes the logic of the problem, the sum principle and the product principle. It is like a cave painting if you want, that depicts the problem.

But GF is a more rigorous expression, so rigorous that it can be immediately translated in computer language. However, when it comes to compute coefficients by hand, the effort is the essentially the same if we attack the initial problem or its GF depicting.

Take for example the recurrence above $$a[n+1,k+1] = a[n,k] + 2.a[n-1,k]$$. It is valid either if we think in terms of days and euros, or if we think it in terms of polynomial coefficients and the effort is mainly the same.

The specific of GF's is that they are self-referring.

$$oneday = pde + cde^2 + ide^2$$ may be read as

$$a \ term \ is \ pde \ or \ cde^2 \ or \ ide^2$$

$$ ce^2 \ contains \ one  \ c  \ and  \ two  \ e's $$

Behind both GF and a problem there is something deeper, sometimes named "a combinatorial species", or a "combinatorial class", or a "combinatorial structure".

The GF and the initial problem have the same "combinatorial structure" and this is why this stuff works.