Bill Allombert on Wed, 29 May 2013 00:18:38 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
new GP loop: forpart() |
Dear PARI developers, I have commited a patch by Pascal and myself that adds GP function to loop over partitions: forpart(v=5,print(v)) Vecsmall([1,1,1,1,1]) Vecsmall([1,1,1,2]) Vecsmall([1,2,2]) Vecsmall([1,1,3]) Vecsmall([2,3]) Vecsmall([1,4]) Vecsmall([5]) Also I have changed the partitions function to provide the same interface as forpart. An unfortunate side effect is that the order of the partitions is reversed. This could be fixed if someone provide a forpart_previous() function. Here the documentation: forpart(X = k,seq,{a = k},{n = k}): Evaluate seq over the partitions X = [x_1,...x_n] of integer k, that is increasing sequences x_1 <= x_2... <= x_n of sum x_1+...x_n = k. Optional parameters n and a can be: * n = nmax (resp. n = [nmin,nmax]) to restrict partitions to have length less than nmax (resp. length between nmin and nmax), where the length is the number of non zero entries. * a = amax (resp. a = [amin,amax]) to restrict the components of X to be to integers less than amax (resp. between amin and amax). By default, remove zero entries on the left except if amin <= 0, in which case nmin is ignored and X is of constant length nmax. Examples: \\ max 3 non-zero terms less than 4 ? forpart(v=5,print(Vec(v)),3,4) [1, 2, 2] [1, 1, 3] [2, 3] [1, 4] Cheers, Bill