A desired combination isn't a set, because you need to include repetition. Instead call it a finite sequence in A = Seq(A).

We won't care about the ordering, even though calling it a sequence does naturally includes ordering. No problem.

If a and b are such finite sequences in A, call a*b the combined sequence of "first do a, then do b"

Ex: Let A = {1, 2, 5} and a,b in Seq(A) given by a(1) = 1, a(2) = 1, a(3) = 5, and b(1) = 5, b(2) = 2.

Then a*b = Seq(A) is given by (a*b)(1) = 1, (a*b)(2) = 1, (a*b)(3) = 5, and (a*b)(4) = 5, (a*b)(5) = 2.

For completeness, assume 0 is not allowed in A, and "{after the sequence is done", all the sequence values are 0.

Then a*b is re-defined by "b starts replacing the 1st occurance of 0 in a"

This is all mumbo-mubo, just for precision's sake.

It's really just that a is a finite "subset" of A, except repetition is allowed. And a*b is just "a union b", except tracking repetitions.

Definition: If , define , and .

Definition: Call that special k in the above definition (length of a).

Definition: If , define by for , and for .

Definition: If , define by . Similarly for .

Define: for all .

Definition: If , define by , and for .

Definition: Let .

All that overhead crap is for a very simple recursive algorithm:

----

The meaning of that is "the combinations of A that sum to n" is the union over every k in A of "the combinations of A that sum to n-k, and then include k".