5
\$\begingroup\$

Find the order (size) of the symmetry group of a finite set of integer points in d-dimensional space.

Input

You will be given the coordinates of a finite set of points in d-dimensional space, in any reasonable form. The dimension d may be any positive integer. You can assume that all coordinates are integers, and that all points are distinct. You can optionally take d itself and/or the number of points as additional parameters.

Output

Output the number of symmetries of the set of points. A symmetry is an isometry of d-dimensional space that maps the set to itself (such as a reflection or a rotation). An isometry can be described by an orthogonal matrix A and a vector b, where a point x is mapped to Ax+b. The number of symmetries is always at least 1 (the identity map). The answer might be infinity, for which you must output any one consistent value that is not a positive integer (such as 0 or -1 or the string "infinity"). The symmetries form a group (but you only need to output its size).

Note that it is not enough to count permutations of the points that preserve distances, because several isometries can give the same permutation (see examples below).

Examples

(0,0),(1,0),(1,1)                                   -> 2
(0,0),(2,1)                                         -> 4
(0,0),(1,0),(0,1),(1,1)                             -> 8
(1,1),(-1,-1),(1,-1),(-1,1)                         -> 8
(0,0),(1,0),(0,2)                                   -> 1
(0,0)                                               -> infinity
(0,5,0),(1,2,3)                                     -> infinity
(0,0,0),(1,1,1),(2,2,2),(3,3,3)                     -> infinity
(0,0,5),(1,0,5),(0,1,5),(1,1,5)                     -> 16
(1,0,0),(0,1,0),(0,0,1)                             -> 12
(2,0,0),(0,2,0),(0,0,2),(2,1,0),(0,2,1),(1,0,2)     -> 3
(1,1,1,1),(1,0,0,0),(0,1,0,0),(0,0,1,0),(0,0,0,1)   -> 24
(0),(1),(2)                                         -> 2
(0),(1),(3)                                         -> 1
(1)                                                 -> 2

Selected explanations

(0,0),(1,0),(0,1),(1,1) is a square: the symmetries are 4 reflections (about diagonals and center-lines), 3 rotations, and the identity, making 8.

(0,0,5),(1,0,5),(0,1,5),(1,1,5) adds a constant 3rd coordinate, so each symmetry of the square can in addition be composed with a reflection in the 3rd coordinate, giving 16 symmetries.

(0,5,0),(1,2,3): endpoints of a line segment. In 3 dimensions the line can be rotated by any angle, giving infinitely many symmetries.

This is . Shortest answer in each language wins.

\$\endgroup\$
7
  • 4
    \$\begingroup\$ Why is (1) infinity instead of 2? \$\endgroup\$
    – gsitcia
    Commented Sep 19 at 17:38
  • 1
    \$\begingroup\$ There should be a test case with infinite isometries and at least as many points as the dimension \$d\$ \$\endgroup\$
    – Tbw
    Commented Sep 19 at 20:01
  • 1
    \$\begingroup\$ I mean for the (1) case what are the symmetries other than \$x \rightarrow x\$ and \$x \rightarrow -x+2\$? Also (1,1,1,1),(1,0,0,0),(0,1,0,0),(0,1,0,0),(0,0,0,1) should have (0,0,1,0) instead of the second (0,1,0,0) \$\endgroup\$
    – gsitcia
    Commented Sep 20 at 4:14
  • \$\begingroup\$ @gsitcia Thanks - both fixed. \$\endgroup\$
    – aeh5040
    Commented Sep 20 at 7:48
  • 1
    \$\begingroup\$ @att That is not an isometry unless a = +1 or -1. \$\endgroup\$
    – aeh5040
    Commented Sep 20 at 9:10

2 Answers 2

4
\$\begingroup\$

Python 3 + numpy + scipy, 380 bytes

from itertools import*
from numpy import*
from scipy.linalg import*
def f(p,d,k):
 p=array(p)*k-sum(p,0);n=[*null_space(p).T];z=r=0;g=[]
 if len(n)>1:return
 for i in p:h=[*g,i];s=linalg.matrix_rank(h);g,r=[g,h][r<s],s
 for t in permutations(p,int(r)):m=solve(g+n,[*t]+n);z+={*map(tuple,int64(rint(p@m)))}=={*map(tuple,p)}and isclose([email protected],identity(d)).all()and 1+len(n)
 return z

Try it online!

\$\endgroup\$
2
\$\begingroup\$

PARI/GP, 124 bytes

a->if(1<r=#a+1-matrank(concat(a,1^a[,1])),oo,n=#a~;n!/#Set([[[(v=a[s,]-a[t,])*v~|t<-p]|s<-p=numtoperm(n,k)]|k<-[1..n!]])<<r)

Attempt This Online!

Takes input as a matrix where each row is the coordinates of a point.

Let \$d\$ be the dimension of the space, and \$d'\$ be the dimension of the affine subspace spanned by the points. If \$d'<d-1\$, there are infinitely many symmetries. If \$d'=d\$, we can simply count the permutations of the points that preserve distances. If \$d'=d-1\$, we can count the number of such permutations, and then multiply it by \$2\$ to account for reflections.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.