I can't figure out a concise way of doing the following (I am using C):
Given a number of variables, n, and a maximum degree, d, I want to generate the corresponding polynomial.
For example, if n = 4, and d = 3, I would want to generate the following: x4 x3 x2 + x4 x3 x1 + x4 x2 x1 + x3 x2 x1 + x4 x3 + x4 x2 + x4 x1 + x3 x2 + x3 x1 + x2 x1 + x4 + x3 + x2 + x1
Each xn is a different variable. The polynomial starts with the largest degree of 3, and goes through all of those monomials, then goes through all quadratics, then linears. This should work for any positive n and d.
I can hard code this with a few nested while loops and ints keeping track of each variable, so I can make it work. But I need to generalize, and I can't figure out how to do that, at least not without a gigantic mass of while or for loops.
So, my question is, what's a good way to generate those variable numbers in the proper order, in a very general way? Thanks.