| Bill Allombert on Wed, 02 Jul 2025 23:29:00 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Re: choosing k elements from a "set", and concat of vecsmall |
On Wed, Jul 02, 2025 at 03:32:20PM -0500, Hans L wrote: > 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]])); > ... > ); You can do s = vecextract(S,s0); instead. > 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])] But this would change the semantic of concat. Cheers, Bill.