choosing k elements from a "set", and concat of vecsmall
Hans L <[email protected]>
| Newsgroups | gmane.comp.mathematics.pari.user |
|---|---|
| Message-ID | <CAFoRp-NPLVNXBgr9pCGpLaQo9JGAxZ7H==iXzyXORVp1egwzCw@mail.gmail.com> |
I often have a need to loop over all "n choose k" elements from a set. The closest builtin functionality I have found for this is to use forsubset, and then build a vector from that with vector as follows: forsubset([#S,k], s0, my(s = vector(k, i, S[s0[i]])); ... ); Is there any more appropriate/efficient way to do such a thing? It seems a little convoluted and odd to me that forsubset can't optionally accept a vector as input. Another somewhat related thing I noticed recently which feels like an oversight is when that concat is presented with a t_VEC and t_VECSMALL, it just inserts the t_VECSMALL as a single element. ? concat([1,2,3],Vecsmall([4,5,6])) %12 = [1, 2, 3, Vecsmall([4, 5, 6])] I found this out because forsubset and forperm seem to always produce t_VECSMALL which I did not previously realize. I realize I can work around this by wrapping the vecsmall in a call to Vec(...) but it feels like this should not be necessary. -Hans