LABTITLE=: 'Finite Groups'
LABAUTHOR=: 'KEI'
LABFOCUS=: 1

NB. =========================================================
Lab Chapter INTRODUCTION
NB. =========================================================
Lab Section A. Group Definition
A finite group of order n is a set of n distinct abstract elements,
with a law of combination for any two elements to form a
"product" such that:

A. Every product of any two elements is a member of the set.

B. The set contains a unit element whose product with any
other element is that element.

C. The associative law holds.

D. Every element has an inverse, whose product is the unit element.

We will treat the law of combination as a function f; that is,
the product of elements a and b is given by a f b, and will attempt
to develop a group (of order 4) whose elements are the first four non-negative integers,
using addition (that is, f=:+):
)
'a b c d'=: i.4

a,b,c,d

f=: +

(a,b,c,d) f table (a,b,c,d) NB. The product table

NB. =========================================================
Lab Section
This table of products clearly violates rule A, since it
includes the elements 4, 5, and 6 that do not belong to the
original set.

This could be rectified by using a function that takes the 4-residue (the remainder on
dividing by 4) of the sum as shown below.

Moreover, this value of f satisfies rules B and D as well:

B. The first row of the table of products shows that 0 is the unit element.

D. Each row of the product table includes the unit element 0 in some
column, and the "header" of that column is therefore the inverse.
For example, the inverse of 3 is 1:
)
f=: 4&|@+

2 + 3
2 f 3

(a,b,c,d) f table (a,b,c,d)

3 f 1

NB. =========================================================
Lab Section
Tests of the associativity of f=:4&|@+ are shown below.
In general, f is associative because addition (+) is. We
have therefore shown that the elements 0, 1, 2, and 3 together
with the rule of combination given by f satisfy the group
properties:
)
(1 f 2) f 3

1 f (2 f 3)

(1 f 2) f (3 f 1)

1 f (2 f 3) f 1

NB. =========================================================
Lab Section B. Group Generators
If a unit element is applied to itself the product is also
the unit element. Moreover it is its own inverse -- the unit
element alone therefore forms a group.

If an element applied to itself yields a different product, the
set of the two of them form a possible group. If the table of their
products includes new elements, they may also be added, and the process
repeated until no new products appear. The resulting set is a group.
)
0 f 0                   NB. The unit element alone forms a group
3 f 3                   NB. The product of 3 with itself yields a new element

3 2 f table 3 2         NB. Which added to 3 produces new elements 1 and 0

3 2 1 0 f table 3 2 1 0 NB. Which complete the group generated by 3

NB. =========================================================
Lab Section
The group generated by the element 2 contains only the elements
2 and 0 -- it is said to be a subgroup of the group 0 1 2 3.

Test the subgroups 0 and 2 0 to see that they satisfy all of the group properties.
)
2 f 2

2 0 f table 2 0

NB. =========================================================
Lab Section C. Higher-order Groups
Higher-order groups may be made in the same manner originally used
for the group of order 4. For example:
)
'a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15'=: ALL =:i.16

f16=:16&|@+

ALL f16 table ALL

NB. =========================================================
Lab Section
Explore the subgroup generated by a4 and f16.

Do likewise with other generators, and find at least one element that
generates the full group.

In doing this the following scheme may be found helpful:
)
g=:a2
g
g f16/ g             NB. / (instead of table) gives "bare" table of products
, g f16/ g           NB. , ravels the table to give the list of products 
g , , g f16 g        NB. Append these products to the group g
~. g , , g f16 g     NB. Nub (~.) removes duplicates
g=: ~. g , , g f16 g NB. New g with appended new products
g
g=: ~. g , , g f16 g
g
g=: ~. g , , g f16 g
g
g=: ~. g , , g f16 g
g

NB. =========================================================
Lab Section D. Generation Adverb
We will use the foregoing process to define an adverb gen such
that f gen e gives further elements of the group defined by
f and generated from the elements e:
)
gen=:1 : '~. y. , , y. u./ y.'

e=:2

e=:f16 gen e
e

e=:f16 gen e
e

e=:f16 gen e
e

e=:f16 gen e  
e             NB. No further shows that the generation is complete

e=:2          NB. Reset e

f16 gen ^:_ e NB. NB. f16 gen to infinite power gives the limit directly

NB. =========================================================
Lab Section E. Alphabets
We will use the term "alphabet" for the list of potential
elements of a group, and will illustrate the fact that the
"abstract" elements may be chosen from any alphabet.

We begin with an alphabet of the letters of English, and a
function nfl that gives "numbers from letters", and its
inverse lfn that gives letters from numbers.

We will use the conjunction &. in the expression f16 &. nfl
to apply f16 "under" nfl, that is, apply nfl, then f16, and
then "restore" the effect of nfl by applying its inverse:
)

   ALPH=:'ABCDEFGHIJKLMNOPQRSTUVWXYZ'   
   nfl=: ALPH& i. 
   nfl 'AC'   
   lfn=:nfl^:_1
   lfn 0 2   
   f16A=: f16 &. nfl "0   
   f16A gen 'AC'   
   f16A gen^:_ 'AC'   
   nfl f16A gen^:_ 'AC'

NB. =========================================================
Lab Section
We now define a "word-alphabet" and use it as we did the alphabet of letters.
)
WALPH=:'zero';'one';'two';'three';'four';'five';'six';'seven'

WALPH

nfw=: WALPH&i.
nfw 'zero';'two'

f8=:8&|@+
f8w=:f8 &. nfw"0
f8w gen 'zero';'two'

f8w gen^:_ 'zero';'two'

f8w gen^:_ <'one'

NB. =========================================================
Lab Section F. Selection From and Permutations
The function { selects from its right argument those elements indexed by its left argument. If the left argument contains all of the possible indices in some order, the result is said to be a "permutation" or "anagram" of the right argument.

Such a list of indices is called a permutation vector. For example:
)
y=:'TRAPS'

0 2 3 { y

3 2 1 0 4 { y NB. An anagram of 'TRAPS'

NB. =========================================================
Lab Section
We will now use boxed permutation vectors as a "permutation alphabet" for elements of groups. The function fp for this group will be selection ({) under open, that is, fp=:{&.> . For example:
)
fp=:{&.>

e=:<4 0 1 3 2

e
fp gen e

fp gen^:_ e

e2=:0 4 3 2 1;1 0 4 2 3

 # fp gen^:_ e2 NB. See display in next panel

NB. =========================================================
Lab Section
)
20 6 $ fp gen^:_ e2

NB. =========================================================
Lab Section
Since the ordering of the elements of a group is immaterial,
it is easy to recognize that the lists 0 2 4 8 and 4 8 2 0
represent the same group. In more extensive cases it may be
helpful to use sorting to bring the lists to a standard order.
For example:
)
sort=:/:~

20 6 $ sort fp gen^:_ e2

NB. =========================================================
Lab Section G. Matrices and Matrix Product
Matrices and matrix product may also be used to represent
groups. For example:
)
m=:<%:-=i.3
mp=:+/ . *
mp&.> gen^:_ m

