17
1
Write a program, that determines whether the multiplication table of the given finite magma represents a group. A magma is a set with a binary operation that is closed, that means
- for all a,b in G, a*b is again in G (Closedness)
Let (G, * ) be a magma. (G, * ) is a group if
- for all a,b,c in G, (a*b) * c = a * (b*c) (Associativity)
- there exists an element e in G such that e * a = a * e = a for all a in G (Existence of neutral Element)
- for all a in G there is a b in G such that a * b = b * a = e where e is the neutral element (Existence of Inverse)
Specs
The input is of a string of n^2-1 characters (one character for each element of the magma, allowed are 0-9,a-z) and just represents the table read row by row, ommiting the operator name. You can assume that the input represents a valid magma (that means each of the elements appers exactly once in the header row/colum).
Example: Here we have the table of Z_4
+ | 0 1 2 3
-----------
0 | 0 1 2 3
1 | 1 2 3 0
2 | 2 3 0 1
3 | 3 0 1 2
The input string will be 012300123112302230133012
. (Or if we use symbols it could also be nezdnnezdeezdnzzdneddnez
). Be aware that the sequence of the elements in the row and in the column do not have to be the same, so the table of Z_4 could also look like so:
+ | 1 3 2 0
-----------
1 | 2 0 3 1
0 | 1 3 2 0
2 | 3 1 0 2
3 | 0 2 1 3
This also means that the neutral element is not necessarily in the first column or first row.
If it is a group, the program has to return the character representing the neutral element. If not it has to return a falsy (distinct from the values 0-9 a-z) value
Test cases
Non-groups can easily be constructed by just altering one digit of the string or by artificially altering the tables defining a operation that contradicts one of the group axioms.
Groups
Trivial
* | x
-----
x | x
xxx
Neutral Element: x
H (quaternion group)
* | p t d k g b n m
-------------------
m | b d t g k p m n
p | m k g d t n p b
n | p t d k g b n m
b | n g k t d m b p
t | g m n p b k t d
d | k n m b p g d t
k | t b p m n d k g
g | d p b n m t g k
ptdkgbnmmbdtgkpmnpmkgdtnpbnptdkgbnmbngktdmbptgmnpbktddknmbpgdtktbpmndkggdpbnmtgk
Neutral Element: n
D_4
* | y r s t u v w x
-------------------
u | u x w v y t s r
v | v u x w r y t s
w | w v u x s r y t
x | x w v u t s r y
y | y r s t u v w x
r | r s t y v w x u
s | s t y r w x u v
t | t y r s x u v w
yrstuvwxuuxwvytsrvvuxwrytswwvuxsrytxxwvutsryyyrstuvwxrrstyvwxusstyrwxuvttyrsxuvw
Neutral Element: y
Z_6 x Z_2
x | 0 1 2 3 5 7 8 9 a b 4 6
---------------------------
0 | 0 1 2 3 5 7 8 9 a b 4 6
1 | 1 2 3 4 0 8 9 a b 6 5 7
2 | 2 3 4 5 1 9 a b 6 7 0 8
7 | 7 8 9 a 6 2 3 4 5 0 b 1
8 | 8 9 a b 7 3 4 5 0 1 6 2
9 | 9 a b 6 8 4 5 0 1 2 7 3
a | a b 6 7 9 5 0 1 2 3 8 4
b | b 6 7 8 a 0 1 2 3 4 9 5
3 | 3 4 5 0 2 a b 6 7 8 1 9
4 | 4 5 0 1 3 b 6 7 8 9 2 a
5 | 5 0 1 2 4 6 7 8 9 a 3 b
6 | 6 7 8 9 b 1 2 3 4 5 a 0
01235789ab46001235789ab4611234089ab6572234519ab67087789a623450b1889ab7345016299ab684501273aab6795012384bb678a0123495334502ab67819445013b67892a5501246789a3b66789b12345a0
Neutral Element: 0
A_4
* | i a b c d e f g h j k l
---------------------------
i | i a b c d e f g h j k l
a | a b i e c d g h f l j k
b | b i a d e c h f g k l j
c | c f j i g k a d l b e h
d | d h k b f l i e j a c g
e | e g l a h j b c k i d f
f | f j c k i g d l a h b e
g | g l e j a h c k b f i d
h | h k d l b f e j i g a c
j | j c f g k i l a d e h b
k | k d h f l b j i e c g a
l | l e g h j a k b c d f i
iabcdefghjkliiabcdefghjklaabiecdghfljkbbiadechfgkljccfjigkadlbehddhkbfliejacgeeglahjbckidfffjckigdlahbegglejahckbfidhhkdlbfejigacjjcfgkiladehbkkdhflbjiecgalleghjakbcdfi
Neutral Element: i
Non-Groups
A loop (Group missing associativity, or a Quasi-Group with neutral element)
* | 1 2 3 4 5
-------------
1 | 1 2 3 4 5
2 | 2 4 1 5 3
3 | 3 5 4 2 1
4 | 4 1 5 3 2
5 | 5 3 2 1 4
12345112345224153335421441532553214
Neutral Element: 1
(2*2)*3 = 4*3 = 5 != 2 = 2*1 = 2*(2*3)
An IP-loop (from http://www.quasigroups.eu/contents/download/2008/16_2.pdf)
* | 1 2 3 4 5 6 7
-----------------
1 | 1 2 3 4 5 6 7
2 | 2 3 1 6 7 5 4
3 | 3 1 2 7 6 4 5
4 | 4 7 6 5 1 2 3
5 | 5 6 7 1 4 3 2
6 | 6 4 5 3 2 7 1
7 | 7 5 4 2 3 1 6
123456711234567223167543312764544765123556714326645327177542316
Neutral Element: 1
2*(2*4) = 2*6 = 5 != 7 = 3*4 = (2*2)*4
Monoid (by Quincunx, thanks!)
Monoids are Magmas with associativity and a neutral element.
* | 0 1 2 3
-----------
0 | 0 1 2 3
1 | 1 3 1 3
2 | 2 1 0 3
3 | 3 3 3 3
012300123113132210333333
Neutral Element: 0
Another Monoid
(Multiplication mod 10, without the 5) We obviously do not have inverses, and the associativity is given by the multiplication modulo 10.
* | 1 2 3 4 6 7 8 9
-------------------
1 | 1 2 3 4 6 7 8 9
2 | 2 4 6 8 2 4 6 8
3 | 3 6 9 2 8 1 4 7
4 | 4 8 2 6 4 8 2 6
6 | 6 2 8 4 6 2 8 4
7 | 7 4 1 8 2 9 6 3
8 | 8 6 4 2 8 6 4 2
9 | 9 8 7 6 4 3 2 1
Neutral Element: 1 12346789112346789224682468336928147448264826662846284774182963886428642998764321
Thought I'd add another table, much bigger, just for fun: http://ideone.com/823aRG
– Justin – 2015-04-19T07:21:56.437Just for fun, here's another really big one that breaks the
– Justin – 2015-04-19T07:37:32.3000-9a-z
rule: http://ideone.com/vC0ewtFor one that knows nothing about groups,magmas and so on, the specs are fuzzy. For instance, are operations commutative? (so the table is redundant). Moreover. the position of neutral in first row is not related to having the same order in row and column: with
10101010
the order is the same and the neutral is in the last row and column – edc65 – 2015-04-19T09:40:39.973@edc Groups are not necessarily commutative (commutative groups are called abelian). The definition of the a group is complete (it is the usual definition), anything additional would provide further restriction. In those tables the multiplication with the neutral element is usually in the first row/column, and the sequence of the elements of the header row/column are usually the same, but you can still write down a valid table without following those conventions, which is what I wanted to include here. – flawr – 2015-04-19T10:12:09.037
If you're curious about the name, there is a question on ELU. What do you expect from a name made up by a made-up French mathematician?
– xebtl – 2015-04-19T10:40:48.1731I deleted some comments which appeared to be obsolete. Please notify me of any comments that should be undeleted. – Martin Ender – 2015-04-19T20:08:50.360