0

Suppose I have some weights: two 2g weights, two 3g weights, and one 4g weight.

I can find all possible weights I can add up to by the following polynomial multiplication:

$(1+x^2+x^4)(1+x^3+x^6)(1+x^4) = x^{14}+x^{12}+x^{11}+2x^{10}+x^9+2x^8+2x^7+2x^6+x^5+2x^4+x^3+x^2+1$

which mean I have 1 way to add up to 14g, 2 ways to add up to 10g, etc.

I wonder how to formulate using polynomial multiplication if I only want to find out what weight and how many ways to add up to that weight using only two of the weights at a time.

Vito
  • 175
  • 6
  • This is an example of a generating function. If you are interested in learning more about generating functions, there are many resources here: How can I learn about generating functions? – awkward May 29 '21 at 13:15
  • I'd like to add that I do not personally think that knowing that this use of polynomials is called "generating function method" gives any insight on the problem. It just turns the question into: "formulate counting problem using generating functions"... I agree that it is very useful to know in general, though, and this is useful for the future readers! :) – Luca Ghidelli May 30 '21 at 05:44

1 Answers1

2

Let me answer one question at a time, starting from your example, where you have three weights, corresponding to polynomials P(x), Q(x), R(x).

Using only two weights at a time

P(x)Q(x) tells you in how many ways you can weigh something using only P and Q, so:

$$P(x) Q(x) + Q(x) R(x) + R(x)P(x)$$ $$ = (1+x^2+x^4)(1+x^3+x^6) + (1+x^3+x^6)(1+x^4)+ (1+x^2+x^4)(1+x^4)+$$ $$= 2 x^{10} + 2 x^8 + 2 x^7 + 3 x^6 + x^5 + 4 x^4 + 2 x^3 + 2 x^2 + 3$$

solves the problem of counting in many ways you can weigh something using only two weights. Note though that we are counting the "zero uses" of a weight as well, so you might want to change slightly, according to your real needs.

I want to find what weights

You could just label P,Q,R with three dummy variables a,b,c like that

$$abP(x) Q(x) + bcQ(x) R(x) + caR(x)P(x)$$ $$ = ab(1+x^2+x^4)(1+x^3+x^6) +bc(1+x^3+x^6)(1+x^4) + c a(1+x^2+x^4)(1+x^4) $$ $$ = (ab+bc) x^{10} + (ab+ca) x^8 + (ab+bc) x^7 + (ab+bc+ca) x^6 + ab x^5 + (ab+bc+2ca) x^4 + (ab+bc) x^3 + (ab+ca) x^2 + (ab+bc+ca) $$

I want to see how many times to add that weight

The simplest way is to attach "the dummy variables a,b,c" to the powers inside the polynomials, in order to "count the number of weights" instead of only "the number of grams" (that is counted using the variable x).

So effectively we will use the polynomials $$A(a, x) = 1+ax^2+a^2x^4$$ $$B(b,x) = 1 + bx^3 + b^2 x^6 $$ $$C(c,x) = 1 + c x^4$$

And the answer to your problem is:

$$A(a,x)B(b,x) + B(b,x)C(c,x) + C(c,x) A(a,x) $$ $$= (1+a x^2+a^2 x^4)(1+bx^3+b^2x^6) +(1+bx^3+b^2x^6)(1+cx^4) + (1+ax^2+a^2x^4)(1+cx^4) $$ $$= (a^2b^2+b^2c^2) x^{10} + (ab^2+ca) x^8 + (a^2b+bc) x^7 + (a^0b^2+b^2c^0+ca) x^6 + ab x^5 + (a^2b^0+b^0c+c^0a^2 + ca^0) x^4 + (a^0b+bc^0) x^3 + (ab^0+c^0a) x^2 + (a^0b^0+b^0c^0+c^0a^0) $$