\Chapter{Basic methods and attributes}

We describe the basic core methods and attributes of the {\LOOPS} package in this chapter.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Basic attributes}

We associate many attributes with quasigroups in order to speed up computation.
This section lists some basic attributes of quasigroups and loops.

The list of elements of a quasigroup $Q$ is obtained by the usual command

\>Elements( <Q> ) A

The Cayley table of a quasigroup $Q$ is returned with

\>CayleyTable( <Q> ) A

One can use `Display( CayleyTable( <Q> ) )' for pretty matrix-style output of
small Cayley tables.

The neutral element of a loop $L$ is obtained via

\>One( <L> ) A

If you want to know if a quasigroup $Q$ has a neutral element, you can find out
with the standard function for magmas

\>MultiplicativeNeutralElement( <Q> ) A

The size of a quasigroup $Q$ is calculated by

\>Size( <Q> ) A

When $L$ is a <power-associative loop>\index{power-associative loop}, i.e., the
powers of elements are well-defined in $L$, the <exponent>\index{exponent} of
$L$ is the smallest positive integer divisible by orders of all elements of
$L$. The following attribute calculates the exponent without testing for
power-associativity:

\>Exponent( <L> ) A

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Basic arithmetic operations}

Each quasigroup element in {\GAP} knows which quasigroup it belongs to. It is
therefore possible to perform arithmetic operations with quasigroup elements
without referring to the quasigroup. All elements involved in the calculation
must belong to the same quasigroup.

Two elements $x$, $y$ of the same quasigroup are multiplied by $x*y$ in {\GAP}.
Since multiplication of at least three elements is ambiguous in the
nonassociative case, we by default parenthesize elements from left to right,
i.e., $x*y*z$ means $((x*y)*z)$. Of course, one can specify the order of
multiplications by providing parentheses.

Universal algebraists introduce two additional operations for quasigroups.
Namely the <left division>\index{left division} $x\backslash y$ defined by
$x\cdot(x\backslash y)=y$, and the <right division>\index{right division} $x/y$
defined by $(x/y)\cdot y=x$. These two operations can be found in {\LOOPS} as:

\>LeftDivision( <x>, <y> ) O
\>RightDivision( <x>, <y> ) O

When $Q$ is a quasigroup, $x$ is an element of $Q$, and $S$ is a list of
elements of $Q$, then

\>LeftDivision( <S>, <x> ) O
\>LeftDivision( <x>, <S> ) O
\>RightDivision( <S>, <x> ) O
\>RightDivision( <x>, <S> ) O

returns the list of elements obtained by performing the respective
division of $S$ by $x$, or of $x$ by $S$, using one element of $S$ at a time.

We also support $/$ in place of `RightDivision'. But we do not support
$\backslash$ in place of `LeftDivision'.

To obtain the Cayley tables for the operation left division or
right division, use

\>LeftDivisionCayleyTable( <Q> ) O
\>RightDivisionCayleyTable( <Q> ) O

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Powers and inverses}

Powers of elements are generally not well-defined in quasigroups. We say that
the quasigroup $Q$ is <power-associative>\index{power-associativity}, if for
any $x\in Q$, the submagma generated by $x$ is associative.

For magmas and positive integer exponents, {\GAP} defines the powers in the
following way: $x^1=x$, $x^{2k}=(x^k)\cdot(x^k)$ and $x^{2k+1}=(x^{2k})\cdot
x$. One can easily see that this returns $x^k$ in $\log_2(k)$ steps. For
{\LOOPS}, we have decided to keep this method, hoping that everybody will use
it with care for non power-associative quasigroups.

Let $x$ be an element of a loop $L$ with neutral element $1$. Then the <left
inverse>\index{left inverse} $x^\lambda$ of $x$ is the unique element of $L$
satisfying $x^\lambda x=1$. Similarly, the <right inverse>\index{right inverse}
$x^\rho$ satisfies $xx^\rho=1$. If $x^\lambda=x^\rho$, we call
$x^{-1}=x^\lambda=x^\rho$ the <inverse>\index{inverse} of $x$.

\>LeftInverse( <x> ) O
\>RightInverse( <x> ) O
\>Inverse( <x> ) O

The following examples illustrates the concept of inverses for a given loop $M$
in which $M$.$i$ coincides with the $i$th element:

\beginexample
gap> CayleyTable( M );
[ [ 1, 2, 3, 4, 5 ],
  [ 2, 1, 4, 5, 3 ],
  [ 3, 4, 5, 1, 2 ],
  [ 4, 5, 2, 3, 1 ],
  [ 5, 3, 1, 2, 4 ] ]
gap> [ LeftInverse( M.3 ), RightInverse( M.3 ), Inverse( M.3 ) ];
[ l5, l4, fail ]
\endexample

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Associators and commutators}

Let $Q$ be a quasigroup and $x$, $y$, $z\in Q$. Then the
<associator>\index{associator} of $x$, $y$, $z$ is the unique element $u$ such
that $(xy)z=(x(yz))u$. The <commutator>\index{commutator} of $x$, $y$ is the
unique element $v$ such that $xy=(yx)v$.

\>Associator( <x>, <y>, <z> ) O
\>Commutator( <x>, <y> ) O

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Generators}

The following two attributes are synonyms of `GeneratorsOfMagma':

\>GeneratorsOfQuasigroup( <Q> ) A
\>GeneratorsOfLoop( <L> ) A

As usual in {\GAP}, one can refer to the $i$th generator of a quasigroup $Q$ by
`Q.i'. Note that it is not necessarily the case that `Q.i = Elements( Q )[ i
]', since the set of generators can be a proper subset of the elements.

It is easy to prove that a quasigroup of order $n$ can be generated by a subset
containing at most $\log_2{n}$ elements. When $Q$ is a quasigroup

\>GeneratorsSmallest( <Q> ) A

returns a generating set $\{q_0$, $\dots$, $q_m\}$ of $Q$ such that
$Q_0=\emptyset$, $Q_m=Q$, $Q_i=\langle q_1$, $\dots$, $q_i \rangle$, $q_{i+1}$
is the least element of $Q\setminus Q_i$.
