Cayley Table of the Dihedral Group \$D_3\$

8

1

The Dihedral group \$D_3\$ represents the symmetries of an equilateral triangle, using the identity (represented by id), rotations (represented by r1 and r2), and reflections (represented by s0, s1, and s2).

Your task is to compute the composition \$yx\$ of the elements \$x, y \in D_3 \$. They are given by the Cayley table below:

  x  id  r1  r2  s0  s1  s2
y  +-----------------------
id | id  r1  r2  s0  s1  s2
r1 | r1  r2  id  s1  s2  s0
r2 | r2  id  r1  s2  s0  s1
s0 | s0  s2  s1  id  r2  r1
s1 | s1  s0  s2  r1  id  r2
s2 | s2  s1  s0  r2  r1  id

Input

Any reasonable input of x and y. Order does not matter.

Output

y composed with x, or looking up values in the table based on x and y.

Test Cases

These are given in the form x y -> yx.

id id -> id
s1 s2 -> r1
r1 r1 -> r2
r2 r1 -> id
s0 id -> s0
id s0 -> s0

Notes on I/O

You may use any reasonable replacement of id, r1, r2, s0, s1, s2, for example 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, or even [0,0], [0,1], [0,2], [1,0], [1,1], [1,2] (here the first number represents rotation/reflection and the second is the index).

qwr

Posted 2018-09-10T21:00:19.927

Reputation: 8 929

Answers

8

Python 2, 27 bytes

lambda o,O:[o[_]for _ in O]

Try it online!

Jonathan Frech

Posted 2018-09-10T21:00:19.927

Reputation: 6 681

can u explain this code? – tarit goswami – 2018-09-16T09:07:29.067

1@taritgoswami Both o and O are three-element lists containing a permutation of the integers 0, 1, 2. In the list comprehension, the former is indexed by the latter, implementing permutation composition. – Jonathan Frech – 2018-09-16T10:25:16.883

3

JavaScript (ES6), 39 bytes

Uses the following mapping:

 id | r1 | r2 | s0 | s1 | s2
----+----+----+----+----+----
 2  | 0  | 4  | 1  | 3  | 5

Takes input as (x)(y).

x=>y=>'450123234523012323'[(x*51^y)%18]

Try it online!


JavaScript (ES6), 20 bytes

Using Jonathan Frech's I/O format:

x=>y=>y.map(n=>x[n])

Try it online!

Arnauld

Posted 2018-09-10T21:00:19.927

Reputation: 111 334

3

Jelly, 1 byte

A dyadic link taking y on the left and x on the right.

Uses the representations of the fist three natural numbers transformed as their actions describe:

   name:  id          r1          r2          s0          s1          s2
  value:  [1,2,3]     [2,3,1]     [3,1,2]     [2,1,3]     [1,3,2]     [3,2,1]
(action:  identity    rot-Left    rot-Right   swap-Left   swap-Right  swap-Outer)

A port of Jonathan Frech's Python answer

is Jelly's "index into" atom, and it vectorises; note that Jelly is 1-indexed.

Try it online! Or see a table using the question-names.


To take x on the left and y on the right, these values may be used instead:

id       r1       r2       s0       s1       s2
[1,2,3]  [3,1,2]  [2,3,1]  [1,3,2]  [3,2,1]  [2,1,3]

...see here.

Jonathan Allan

Posted 2018-09-10T21:00:19.927

Reputation: 67 804

3

Python 2, 27 26 23 bytes

lambda x,y:(y+x*5**y)%6

Try it online! Edit: Saved 3 bytes thanks to @NieDzejkob. Uses the following mapping:

 id | r1 | r2 | s0 | s1 | s2 
----+----+----+----+----+----
 0  | 2  | 4  | 1  | 3  | 5  

Neil

Posted 2018-09-10T21:00:19.927

Reputation: 95 035

@JonathanFrech ... I don't have x*-1... I have x*(-1**y) – Neil – 2018-09-12T11:16:13.060

@JonathanFrech Ah, I'd typoed my test code, I thought I was getting (-1)**y. Oh well, that's still 1 byte shorter... – Neil – 2018-09-12T13:18:38.340

Hm ... And I thought I golfed a byte ... – Jonathan Frech – 2018-09-12T16:36:43.050

Like on the D4 challenge, you can replace (-1) with 5 for -3 bytes. – NieDzejkob – 2019-05-04T14:11:46.147

2

APL (Dyalog Classic), 3 bytes

+.×

Try it online!

+.× is matrix multiplication

we represent the group as

id     r1     r2     s0     s1     s2
1 0 0  0 0 1  0 1 0  0 0 1  0 1 0  1 0 0 
0 1 0  1 0 0  0 0 1  0 1 0  1 0 0  0 0 1 
0 0 1  0 1 0  1 0 0  1 0 0  0 0 1  0 1 0 

ngn

Posted 2018-09-10T21:00:19.927

Reputation: 11 449

2

K (ngn/k), 1 byte

@

Try it online!

x@y is list indexing, which is the same as composition of permutations; we represent the group as

id:0 1 2; r1:1 2 0; r2:2 0 1; s0:2 1 0; s1:1 0 2; s2:0 2 1

ngn

Posted 2018-09-10T21:00:19.927

Reputation: 11 449

1

Shaggy

Posted 2018-09-10T21:00:19.927

Reputation: 24 623

1

JavaScript (Node.js), 24 19 bytes

(x,y)=>(y+x*5**y)%6

Try it online! Edit: Saved 2 bytes by switching to ** and 3 bytes thanks to @NieDzejkob. Uses the following mapping:

 id | r1 | r2 | s0 | s1 | s2 
----+----+----+----+----+----
 0  | 2  | 4  | 1  | 3  | 5  

The old 24 byte version also works in old versions of JavaScript:

(x,y)=>(y%2?y+6-x:y+x)%6

Neil

Posted 2018-09-10T21:00:19.927

Reputation: 95 035

1

Racket, 42 bytes

(lambda(x y)(modulo(+ y(* x(expt 5 y)))6))

Try it online!

A boring port of Neil's Python answer. Uses the same I/O format, so:

 id | r1 | r2 | s0 | s1 | s2 
----+----+----+----+----+----
 0  | 2  | 4  | 1  | 3  | 5  

Comrade SparklePony

Posted 2018-09-10T21:00:19.927

Reputation: 5 784

0

05AB1E, 1 byte

è

Port of @JonathanAllan's Jelly answer, but with 0-based indices, so the representations are:

id       r1       r2       s0       s1       s2       # Original values
[0,1,2]  [1,2,0]  [2,0,1]  [1,0,2]  [0,2,1]  [2,1,0]  # Values instead

Try it online or verify all possible combinations or verify all mapped back to ids.

Explanation:

è  # Index the second (implicit) input-list vectorized into the first (implicit) input-list
   # And output the result implicitly

Kevin Cruijssen

Posted 2018-09-10T21:00:19.927

Reputation: 67 575

0

Wolfram Language (Mathematica), 16 bytes

Mod[#+#2*5^#,6]&

Try it online!

Another boring port of Neil's answer, this time in Mathematica. It is an anonymous function that takes arguments in the order [y, x].

Here’s the input representation:

 id | r1 | r2 | s0 | s1 | s2 
----+----+----+----+----+----
 0  | 2  | 4  | 1  | 3  | 5 

Comrade SparklePony

Posted 2018-09-10T21:00:19.927

Reputation: 5 784