Charles Greathouse on Tue, 06 Feb 2024 17:47:25 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Looping over ordered partitions


The looping commands force and forpart are very convenient. I have a problem I was working on which is looking for the smallest vector (in terms of vecsum) with a certain property. What is the best way to perform such a search in PARI/GP?

In my case I have dimension/vector length 11 and sum < 31. (I have an instance with sum 31 but it's probably not optimal.)

I can do a forvec, but even forvec(v=vector(11,i,[1,7]), ...) takes a long time (and spends a lot of time looking at values with sum > 30), and I miss instances with numbers larger than 7. Or else I can use forpart but then I need to permute the values (and in my case I definitely have duplicate values, so naive 11! permutations are wasteful and slow).

(I'm not asking for any new commands here, just the best way to solve my problem at hand.)