function like Mathematica's Tuples



On 5/18/10, Mario Rodriguez <biomates at telefonica.net> wrote:

> (%i1) tuples(lis, n) :=
>   block(
>     [ len_lis, aux_lis, aux_set, cart_prod],
>     len_lis : length(lis),
>     aux_lis : makelist(k,k,1,len_lis),
>     aux_set : setify(aux_lis),
>     cart_prod : apply(cartesian_product, makelist(aux_set,k,1,n)),
>     subst(map("=", aux_lis, lis), listify(cart_prod)) ) $

This is interesting, but I don't think it works correctly,
because subst makes serial substitutions where I think
you want parallel substitution.
e.g. tuples([3, 2, 1], 2) yields something incorrect, right?

sublis makes substitutions in parallel but it seems to want
symbols, not integers, on the left-hand side of "=".
Someone was working on a parallel version of subst;
whatever happened to that?

best

Robert Dodier