In general there are $n^m$ total ways of writing down $m$ objects from a set of $n$ objects. Listing all possible combinations will have a $\mathcal{O}(n^m)$ complexity and can be done via using $m$ for-loops in a programming language.
If we look at the problem of choosing $m$ elements from a set of $n$ elements with replacement for small $n$, e.g. $n=4$, and large enough $m$, there are $${{n+m-1}\choose{m}}\approx \mathcal{O}(m^3)$$ cases in total.
This suggests that one may find an algorithm which lists all such elements with cubic complexity.
Here is an example: Let $m=3$ and $n=3$ corresponding to the set $\{0,1,2\}$. I would like to pick $m=3$ elements and I have ${{3+3-1}\choose{3}}=10$ different elements of my set.
Here are the elements:
$1. \{\{0,1,2\},\{0,2,1\},\{1,0,2\},\{1,2,0\},\{2,1,0\},\{2,0,1\}\}$
$2. \{\{0,0,0\}\}$
$3. \{\{1,1,1\}\}$
$4. \{\{2,2,2\}\}$
$5. \{\{0,0,1\},\{0,1,0\},\{1,0,0\}\}$
$6. \{\{0,2,0\},\{2,0,0\},\{0,0,2\}\}$
$7. \{\{1,2,1\},\{1,1,2\},\{2,1,1\}\}$
$8. \{\{1,1,0\},\{1,0,1\},\{0,1,1\}\}$
$9. \{\{2,2,0\},\{2,0,2\},\{0,2,2\}\}$
$10. \{\{1,2,2\},\{2,1,2\},\{2,2,1\}\}$
Given the original set $\{0,1,2\}$, one can list all those $10$ sets with $\mathcal{O}(m^n)$ complexity. First we list all possible combinations: $\{\{0,0,0\},\{0,0,1\},\ldots,\{2,2,2\}\}$. Then for all element we get, we make all possible permutations and remove all the same elements from the set and move to the next element and so on. This requires one to list first of all, all possible combinations, which requires $n^m$ complexity. I am wondering if there is an efficient algorithm which can do the same thing in cubic complexity.
My aim is actually to sum up the indexes of my vectors given by those $10$ index sets. I have $3$ vectors $v_1,v_2,v_3$ each indexed from $0$ to $2$, I would like to get a vector which sums the indexes as given by those $10$ cases. For example,
$v(1)=v_1(0)v_2(1)v_3(2)+v_1(0)v_2(2)v_3(1)+v_1(1)v_2(0)v_3(2)+v_1(1)v_2(2)v_3(0)+v_1(2)v_2(1)v_3(0)+v_1(2)v_2(0)v_3(1)$
$v(2)=v_1(0)v_2(0)v_3(0)$
$v(3)=v_1(1)v_2(1)v_3(1)$
$v(4)=v_1(2)v_2(2)v_3(2)$
...
$v(10)=v_1(1)v_2(2)v_3(2)+v_1(2)v_2(1)v_3(2)+v_1(2)v_2(2)v_3(1)$
and so on.
Question: Is it possible to list all such elements with no more than cubic complexity? Or in other words is there an efficient way of computing my vector $v$, given $v_1,v_2,v_3$.
Note: The order of indexes of vector $v$ is not important. Namely the algorithm can calculate $v$ as any permuted way of the $v$ that I described above, e.g. $v(0):=v(6)$ and $v(6):=v(0)$ is no problem.