GroupStabilizer
allows you to include an action function f
via GroupStabilizer[group, {p1, p2, ...}, f]
! The syntax GroupStabilizer[group, {p1, p2, ...}, f]
asks for the simultaneous stabilizer of all of the points {p1, p2, ...}
, but here we just want the stabilizer of a single point blists
, so we'll expect to use GroupStabilizer[group, {blists}, f]
.
If these are bona-fide sets at both levels (and not lists), we can canonicalize the form of a set by using Sort[Sort /@ blists]
(sorting each inner list, then the whole list of lists). (You already have this in your solution implicitly, but just to put this here for the general audience; likewise for some of the following!)
So, our action function can be defined as follows. It expects to take in a point (here, blists
) as first argument, and a group element g
as a second argument. Luckily, the usual action PermutationReplace
replaces at every level of the expression, so we can just apply it to the entire blists
and then canonicalize:
f[blists_, g_] := Sort[Sort /@ PermutationReplace[blists, g]]
Then
matroidAuts[blists_] :=
GroupStabilizer[SymmetricGroup[Max@Flatten[blists]],
{Sort[Sort /@ blists]}, f]
should work, but I haven't been able to test it. Let me know if it does!
Update: benchmarking
Using
RandomM[n_] := Sort[Sort /@ RandomInteger[{1, n}, {n, n}]]
m = M[8];
your code finishes in about half a second, whereas mine takes about 17 (!). I'm honestly pretty surprised that the built-in function is worse than brute-forcing it—what is the built-in function even doing?!
They seem to give the same (trivial group) answer. I don't know how they'd fare in the nontrivial case yet, but I can't imagine it'd be much different!
I tried speeding up your code by using Sow
and Reap
, and (separately) by using Select
, but only shaved off a tiny bit. Select
seemed faster by a hair. In general, though, when you're building big lists (which we're not in this benchmark, since the automorphism group is often trivial), AppendTo
is slow. I'll put my code here in case it's of any use!
matroidauts2[M0_] := With[{M = Sort[Sort /@ M0]},
PermutationGroup @
Select[GroupElements[SymmetricGroup[Max[Flatten[M]]]],
(M == Sort[Sort /@ PermutationReplace[M, #]]) &]]
matroidauts3[M0_] := With[{M = Sort[Sort /@ M0]},
PermutationGroup @
First[Last[
Reap[
If[M == Sort[Sort /@ PermutationReplace[M, #]], Sow[#]] & /@
GroupElements[SymmetricGroup@Max@Flatten[M]];]]]]