Re: set partitions, or mutually disjoint subsets

"Ruud H.G. van Tol" <[email protected]> Fri, 12 Dec 2025 15:35:07 +0100
Newsgroups gmane.comp.mathematics.pari.user
Message-ID <[email protected]>
On 2025-12-11 00:53, Ruud H.G. van Tol wrote:
 > On 2025-12-09 14:18, Ruud H.G. van Tol wrote:
 >> Mainly for fun, and to learn more about pari,
 >> I'm looking for an efficient way to transform a number N (width)
 >> into a set of K (binary) vectors (each of length K and at least one 1).
 >
 > One way to do it:

That wasn't good.


A little better:

{ vec_xor(v)= my(t=0);[t=bitxor(t,e)|e<-v];t; }

{ my( n=10, k=3, s=2^n-1, r=[], t, g=primes(n)~, h=vecsum(g) );
   setsearch( divisors(h), k) || return;
   h/= k;

   forpart(p=s
   , (s == vec_xor(p)) || next;
     t= vecsort([Vecrev(digits(e,2),n)|e<-p]);
     foreach(t,f, (h == f*g) || next(2));
     print([(matdiagonal(f)*g)~|f<-t]);
     r= concat(r,[t])
   ,
   , [k,k]
   );
}

[[0, 0, 0, 0, 11, 13, 0, 19, 0, 0], [0, 3, 0, 0, 0, 0, 17, 0, 23, 0], 
[2, 0, 5, 7, 0, 0, 0, 0, 0, 29]]
[[0, 0, 0, 7, 0, 13, 0, 0, 23, 0], [0, 3, 0, 0, 11, 0, 0, 0, 0, 29], [2, 
0, 5, 0, 0, 0, 17, 19, 0, 0]]
[[0, 0, 0, 7, 0, 0, 17, 19, 0, 0], [0, 3, 0, 0, 11, 0, 0, 0, 0, 29], [2, 
0, 5, 0, 0, 13, 0, 0, 23, 0]]


But this does many skips in for-loops, something I like to get rid of.

Am now looking into bin-packing examples, see also https://oeis.org/A331541.

-- Ruud