Let's say we've got $n$ numbers to multiply together. But the multiplication operation, like in computer floating-point arithmetics, is not associative. Thus the order of multiplication matters.
Furthermore let's say that we want to minimize the nesting of the expression tree that represents the entire multiplication, so the expression/multiplication tree is the minimum-height binary tree with $n$ leaves.
We want to iterate through all possible ways to multiply the $n$ numbers together.
A way to do it would be to iterate through all permutations of the $n$ numbers (each number is given a position as a leaf of a binary tree), but that would be wasteful, as it would take no advantage of the commutativity property that does hold for this multiplication operation.
Example, $n = 3$: let's call our three numbers $n_1$, $n_2$, $n_3$. There are $3! = 6$ permutations of these three numbers:
123 132 213 231 312 321
The above permutations correspond to these multiplication expressions: $$ (n_1 n_2)n_3 $$ $$ (n_1 n_3)n_2 $$ $$ (n_2 n_1)n_3 $$ $$ (n_2 n_3)n_1 $$ $$ (n_3 n_1)n_2 $$ $$ (n_3 n_2)n_1 $$
However, there are only three equivalence classes when we account for commutativity of the multiplication operation: $$ (n_1 n_2)n_3 = (n_2 n_1)n_3 $$ $$ (n_2 n_3)n_1 = (n_3 n_2)n_1 $$ $$ (n_1 n_3)n_2 = (n_3 n_1)n_2 $$
The goal is to iterate through at least one member of each equivalence class relatively efficiently (better than factorial time), with as little redundancy as possible. So with $n = 3$ we'd ideally iterate through only three permutations, e.g.:
123 132 231
As for the binary trees mentioned above, consider, for example, $n = 4$: we're only interested in expressions with minimal nesting, so $(n_1 n_2)(n_3 n_4)$ is OK, but $((n_1 n_2)n_3)n_4$ isn't, we do not want to iterate through an expression with non-minimal nesting.
In case someone is interested in the motivation for this question, see here: https://math.stackexchange.com/questions/4611399/numerically-stable-evaluation-of-factored-univariate-real-polynomial
To sum up, the goal is to iterate through all equivalence classes of multiplication expressions with minimal nesting, and to do it as efficiently as possible, i.e., I hope I can avoid generating all permutations.