Is the group cyclic?

21

3

Introduction

You can skip this part if you already know what a cyclic group is.

A group is defined by a set and an associative binary operation $ (that is, (a $ b) $ c = a $ (b $ c). There exists exactly one element in the group e where a $ e = a = e $ a for all a in the group (identity). For every element a in the group there exists exactly one b such that a $ b = e = b $ a (inverse). For every two elements a, b in the group, a $ b is in the group (closure).

We can write a^n in place of a$a$a$...$a.

The cyclic subgroup generated by any element a in the group is <a> = {e, a, a^2, a^3, a^4, ..., a^(n-1)} where n is the order (size) of the subgroup (unless the subgroup is infinite).

A group is cyclic if it can be generated by one of its elements.

Challenge

Given the Cayley table (product table) for a finite group, determine whether or not it's cyclic.

Example

Let's take a look at the following Cayley table:

1 2 3 4 5 6
2 3 1 6 4 5
3 1 2 5 6 4
4 5 6 1 2 3
5 6 4 3 1 2
6 4 5 2 3 1

(This is the Cayley table for Dihedral Group 3, D_3).

This is 1-indexed, so if we want to find the value of 5 $ 3, we look in the fifth column on the third row (note that the operator is not necessarily commutative, so 5 $ 3 is not necessarily equal to 3 $ 5. We see here that 5 $ 3 = 6 (also that 3 $ 5 = 4).

We can find <3> by starting with [3], and then while the list is unique, append the product of the last element and the generator (3). We get [3, 3 $ 3 = 2, 2 $ 3 = 1, 1 $ 3 = 3]. We stop here with the subgroup {3, 2, 1}.

If you compute <1> through <6> you'll see that none of the elements in the group generate the whole group. Thus, this group is not cyclic.

Test Cases

Input will be given as a matrix, output as a truthy/falsy decision value.

[[1,2,3,4,5,6],[2,3,1,6,4,5],[3,1,2,5,6,4],[4,5,6,1,2,3],[5,6,4,3,1,2],[6,4,5,2,3,1]] -> False (D_3)
[[1]] -> True ({e})
[[1,2,3,4],[2,3,4,1],[3,4,1,2],[4,1,2,3]] -> True ({1, i, -1, -i})
[[3,2,4,1],[2,4,1,3],[4,1,3,2],[1,3,2,4]] -> True ({-1, i, -i, 1})
[[1,2],[2,1]] -> True ({e, a} with a^-1=a)
[[1,2,3,4,5,6,7,8],[2,3,4,1,6,7,8,5],[3,4,1,2,7,8,5,6],[4,1,2,3,8,5,6,7],[5,8,7,6,1,4,3,2],[6,5,8,7,2,1,4,3],[7,6,5,8,3,2,1,4],[8,7,6,5,4,3,2,1]] -> False (D_4)
[[1,2,3,4,5,6],[2,1,4,3,6,5],[3,4,5,6,1,2],[4,3,6,5,2,1],[5,‌​6,1,2,3,4],[6,5,2,1,‌​4,3]] -> True (product of cyclic subgroups of order 2 and 3, thanks to Zgarb)
[[1,2,3,4],[2,1,4,3],[3,4,1,2],[4,3,1,2]] -> False (Abelian but not cyclic; thanks to xnor)

You will be guaranteed that the input is always a group.

You may take input as 0-indexed values.

HyperNeutrino

Posted 2017-09-24T18:40:44.693

Reputation: 26 575

Is 0-indexed input allowed? (e.g. [[0,1,2,3],[1,2,3,0],[2,3,0,1],[3,0,1,2]])? – Neil – 2017-09-24T18:52:02.170

@Neil Yes; I forgot to specify. Thanks! – HyperNeutrino – 2017-09-24T18:52:26.607

@H.PWiz [[2,1],[1,2]] :P – HyperNeutrino – 2017-09-24T18:56:09.410

Truthy test case: [[1,2,3,4,5,6],[2,1,4,3,6,5],[3,4,5,6,1,2],[4,3,6,5,2,1],[5,6,1,2,3,4],[6,5,2,1,4,3]] (product of cyclic groups of orders 2 and 3). – Zgarb – 2017-09-24T19:44:40.553

@Zgarb Thanks, I'll add that – HyperNeutrino – 2017-09-24T19:45:39.427

5You should premute the labels of your group elements more in the test cases. Right now the first row and column of the table is always [1..n] which may be hiding flaws in some answers. – Lynn – 2017-09-24T19:51:53.710

@Lynn Hmm good idea. I'll take one of my truthy cases and permute it. thanks for the suggestion – HyperNeutrino – 2017-09-24T19:53:48.130

3It looks like checking if the group is abelian suffices to pass the test cases. Test cases like Z_2 * Z_2 would fix this. – xnor – 2017-09-25T03:34:51.347

@xnor That does seem to be an issue; thanks. However, I'm not quite sure what Z_2 * Z_2 means? – HyperNeutrino – 2017-09-25T12:00:03.827

2

@HyperNeutrino: That's the direct product of the two-element group with itself -- also known as the Klein four-group.

– hmakholm left over Monica – 2017-09-25T15:47:10.660

@Lynn the 0 and 1 rows/columns of a Cayley table are always trivial: 0e = 0, 1e = e. We could have a bonus problem where one has to decide whether the Cayley table corresponds to a group. Or even decide between {cyclic, non-cyclic abelian, non-abelian, not a group}. – Acccumulation – 2017-09-25T19:09:09.290

@HenningMakholm thanks – HyperNeutrino – 2017-09-25T22:39:21.183

@xnor Isn't Klein 4 abelian too though? – HyperNeutrino – 2017-09-25T22:39:33.587

@HyperNeutrino It is, but it isn't cyclic. – xnor – 2017-09-25T22:46:25.773

@xnor facepalm right. thanks; I'll add that! – HyperNeutrino – 2017-09-25T22:59:51.570

Answers

8

Husk, 11 10 9 bytes

VS≡`ȯU¡!1

1-based. Returns the index of a generator if one exists, 0 otherwise. Try it online!

Explanation

V          Does any row r of the input satisfy this:
      ¡!    If you iterate indexing into r
   `    1   starting with 1
    ȯU      until a repetition is encountered,
 S≡         the result has the same length as r.

Zgarb

Posted 2017-09-24T18:40:44.693

Reputation: 39 083

8

J, 8 bytes

1:e.#@C.

Try it online!

Explanation

1:e.#@C.  Input: matrix M
      C.  Convert each row from a permutation to a list of cycles
    #@    Number of cycles in each row
1:        Constant function 1
  e.      Is 1 a member of the cycle lengths?

miles

Posted 2017-09-24T18:40:44.693

Reputation: 15 654

This could also be 1 e.#@C., fwiw – Conor O'Brien – 2017-09-25T17:44:01.490

Huh, J beats Jelly‽ – Adám – 2017-09-25T23:55:10.120

@Adám Jelly doesn't have a builtin to convert permutations between direct and cycle notation. I could probably add them as atoms later, making ŒCL€1e for 6 bytes in Jelly. – miles – 2017-09-26T00:07:50.503

4

Jelly, 13 11 bytes

ị"⁸$ÐĿ«/E€Ẹ

Try it online!

miles

Posted 2017-09-24T18:40:44.693

Reputation: 15 654

3

JavaScript (ES6), 52 bytes

a=>a.some(b=>!a[new Set(a.map(_=>r=b[r],r=0)).size])

Neil

Posted 2017-09-24T18:40:44.693

Reputation: 95 035

3

Python 2, 96 91 97 bytes

lambda x:any(g(r,r[i],i+1)==len(r)for i,r in enumerate(x))
g=lambda x,y,z:y==z or 1+g(x,x[y-1],z)

Try it online!

Halvard Hummel

Posted 2017-09-24T18:40:44.693

Reputation: 3 131

or 1+g -> or-~g. – Jonathan Frech – 2017-09-25T03:10:17.447

2

Jelly, 15 bytes

JŒ!ị@€µṂ⁼Jṙ'’$$

Try it online!

First silly idea that came to mind: check for isomorphism to Zn. (This code is O(n!)…)

JŒ!ị@€             Generate all ways to denote this group.
                     (by indexing into every permutation of 1…n)
      µṂ⁼          Is the smallest one equal to this?
         Jṙ'’$$      [[1 2 …  n ]
                      [2 3 …  1 ]    (the group table for Z_n)
                      [… … …  … ]
                      [n 1 … n-1]]

Lynn

Posted 2017-09-24T18:40:44.693

Reputation: 55 648

Huh this is an interesting approach; never thought of that! +1 – HyperNeutrino – 2017-09-24T19:51:12.853

2

R, 101 97 bytes

function(m)any(sapply(1:(n=nrow(m)),function(x)all(1:n%in%Reduce(`[`,rep(list(m[x,]),n),x,T,T))))

Verify all test cases

This simply computes <g> for each g \in G and then tests if G \subseteq <g>, then checks if any of those are true. However, since we're always applying $g on the right, we replicate m[g,] (the gth row) and then index into that row with the result of applying $g, accumulating the results rather than using m[g,g$g] every time, which saved about 4 bytes.

Giuseppe

Posted 2017-09-24T18:40:44.693

Reputation: 21 077

1

Clojure, 68 bytes

#(seq(for[l % :when(apply distinct?(take(count l)(iterate l 0)))]l))

NikoNyrh

Posted 2017-09-24T18:40:44.693

Reputation: 2 361

1

Python 2, 82 bytes

lambda A:len(A)in[len(set(reduce(lambda a,c:a+[A[a[-1]][n]],A,[n])))for n in A[0]]

Try it online!

0-indexed Cayley table is input; True/False output for cyclic/non-cyclic group.

Chas Brown

Posted 2017-09-24T18:40:44.693

Reputation: 8 959