14
Definitions
You can skip this part if you already know the definitions of groups, finite groups, and subgroups.
Groups
In abstract algebra, a group is a tuple (G, ∗), where G is a set and ∗ is a function G × G → G such that the following holds:
Closure: for all x, y in G, x ∗ y is also in G (implied by the fact that ∗ is a function G × G → G).
Associativity: for all x, y, z in G, (x ∗ y) ∗ z = x ∗ (y ∗ z).
Identity: there exists an element e in G such that for all x in G, x ∗ e = x = e ∗ x.
Inverse: for each x in G, there exists an element y in G such that x ∗ y = e = y ∗ x, where e is the identity element mentioned in the previous bullet point.
Finite groups
A finite group is a group (G, ∗) where G is finite, i.e. has finitely many elements.
Subgroups
A subgroup (H, ∗) of a group (G, ∗) is such that H is a subset of G (not necessarily proper subset) and (H, ∗) is also a group (i.e. satisfies the 4 criteria above).
Examples
Consider the dihedral group D3 (G, ∗) where G = {1, A, B, C, D, E} and ∗ is defined below (a table like this is called a Cayley table):
∗ | 1 A B C D E --+---------------------- 1 | 1 A B C D E A | A B 1 D E C B | B 1 A E C D C | C E D 1 B A D | D C E A 1 B E | E D C B A 1
In this group, the identity is 1. Also, A and B are inverses of each other, while 1, C, D, and E are the inverses of themselves respectively (the inverse of 1 is 1, the inverse of C is C, the inverse of D is D, and the inverse of E is E).
Now, we can verify that (H, ∗) where H = {1, A, B} is a subgroup of (G, ∗). For the closure, refer to the table below:
∗ | 1 A B --+---------- 1 | 1 A B A | A B 1 B | B 1 A
where all possible pairs of elements in H under ∗ give a member in H.
The associativity does not require checking, since elements of H are elements of G.
The identity is 1. This must be the same with the group identity. Also, the identity in a group must be unique. (Can you prove this?)
For the inverse, check that the inverse of A is B, which is a member of H. The inverse of B is A, which is also a member of H. The inverse of 1 is still itself, which does not require checking.
Task
Description
Given a finite group (G, ∗), find the number of its subgroups.
Input
For a group (G, ∗), you will receive a 2D array of size n × n, where n is the number of elements in G. Assume that index 0 is the identity element. The 2D array will represent the multiplication table. For example, for the group above, you will receive the following 2D array:
[[0, 1, 2, 3, 4, 5],
[1, 2, 0, 4, 5, 3],
[2, 0, 1, 5, 3, 4],
[3, 5, 4, 0, 2, 1],
[4, 3, 5, 1, 0, 2],
[5, 4, 3, 2, 1, 0]]
For example, you can see that 3 ∗ 1 = 5 because a[3][1] = 5, where a is the 2D array above.
Notes:
- You can used 1-indexed 2D array.
- The row and the column for the identity can be omitted.
- You may use other formats as you see fit, but it must be consistent. (i.e. you may want the last index to be identity instead, etc.)
Output
A positive number representing the number of subgroups in the group.
For example, for the group above, (H, ∗) is a subgroup of (G, ∗) whenever H =
- {1}
- {1, A, B}
- {1, C}
- {1, D}
- {1, E}
- {1, A, B, C, D, E}
Therefore, there are 6 subgroups, and your output for this example should be 6.
Hints
You can read the articles that I linked to. Those articles contain theorems about groups and subgroups that might be useful to you.
Scoring
This is code-golf. Answer with lowest byte-count wins.
Oh it wasn't clear to me the e specifically refers to the identity element, not just any intermediate result. – orlp – 2017-04-25T16:42:33.630
@orlp clarified. – Leaky Nun – 2017-04-25T16:43:08.933
If you're going to call
0the identity element, then it's confusing to have the operator described as multiplication... – Neil – 2017-04-25T16:43:57.010@Neil eh... when conventions clash. – Leaky Nun – 2017-04-25T16:45:10.907
@Downvoter: how can I improve my question? – Leaky Nun – 2017-04-25T16:50:20.063
Can we take the identity as 1? – Dennis – 2017-04-25T19:23:32.730
@Dennis I was assuming that the identity element could be any element. Maybe we need more test cases. – mbomb007 – 2017-04-25T19:31:49.803
@mbomb007 Hm, yes, the worked example uses 1. – Dennis – 2017-04-25T19:33:02.787
But it also shows it as
0when it shows the 2D list input. I'd also like to know if the identity element will always be the first item in the first row of the Cayley table. – mbomb007 – 2017-04-25T19:33:44.1431I assumed the elements in the 2D list were identical to the indices of their rows/columns, otherwise how would you even identify which row/column goes with which? – Ørjan Johansen – 2017-04-25T19:44:56.917
@Dennis I just assumed it is
0out of convenience. Doesn't make much sense if the second element is the identity. You can still use it though. I've edited the question. – Leaky Nun – 2017-04-26T01:05:54.300@mbomb007 I've edited the question. – Leaky Nun – 2017-04-26T01:06:54.867