Joerg Arndt on Sat, 01 Jun 2013 19:46:23 +0200


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

Re: new GP loop: forpart()


* Bill Allombert <Bill.Allombert@math.u-bordeaux1.fr> [May 30. 2013 14:06]:
> 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.

With "reversed" you mean: they are lists in ascending order?

For descending lists see
  http://jjj.de/fxt/demo/comb/index.html#partition-desc

Contrary to recent publications, the generator is
faster than the one for ascending lists, at the price
of a single extra integer recording the position of the
(second) last descent.

The partitions appear ordered wrt. to their largest
part, which can be convenient.


> This could be fixed if someone provide a forpart_previous()
> function.

Please see
  http://jjj.de/fxt/demo/comb/index.html#partition-asc
programmed and uploaded a minute ago.  There, in
  http://jjj.de/fxt/demo/comb/partition-asc.h
see the method prev()

Benchmarks at end of the demo-code


> [...]

I can offer a significantly more general generator:
  http://jjj.de/fxt/demo/comb/index.html#composition-nz-restrpref
It can generate compositions (as list of parts)
wrt. to a given condition.  This gives you partitions
as decreasing or increasing lists, into odd parts,
distinct parts, with max rise/fall, modulo conditions...
Indeed any condition that is a condition on prefixes
(this is _quite_ general in practice).

Best,   jj