#include "sort/equivclasses.h" // equivalence_classes() #include "sort/sortbykey.h" // sort_by_key() #include "bits/revbin.h" // revbin() //#include "perm/permrand.h" // random_permute() #include "bits/print-bin.h" // print_bin() #include "nextarg.h" // NXARG() #include "fxttypes.h" // ulong //#include "bits/bitsperlong.h" #include "fxtio.h" #include "fxtalloca.h" //% Equivalence classes: bit-strings with reversal and complement. // Entry A005418 in the OEIS. static ulong nb; // number of bits static ulong mm; // mask to complement bool bs_equiv_q(ulong x, ulong y) // identify words that are mutal reverses { if ( x==y ) return 1; if ( x==revbin(y, nb) ) return 1; return 0; } // ------------------------- bool bsu_equiv_q(ulong x, ulong y) // unlabeled bit-strings { if ( bs_equiv_q(y, x) ) return 1; x ^= mm; if ( bs_equiv_q(y, x) ) return 1; return 0; } // ------------------------- int main(int argc, char **argv) { nb = 6; NXARG(nb, "Number of bits of bit-strings (0 unlabeled bit-strings)."); ulong ksq = 0; NXARG(ksq, "Whether to print key-sorted array."); ALLOCA(ulong, s, n); for (ulong k=0; k