<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<!-- %% -->
<!-- %W  domain.tex                GAP documentation             Thomas Breuer -->
<!-- %W                                                         & Frank Celler -->
<!-- %W                                                     & Martin Schönert -->
<!-- %W                                                       & Heiko Theißen -->
<!-- %% -->
<!-- %H  @(#)<M>Id: domain.tex,v 4.9 2000/09/15 15:00:14 gap Exp </M> -->
<!-- %% -->
<!-- %Y  Copyright 1997,  Lehrstuhl D für Mathematik,  RWTH Aachen,   Germany -->
<!-- %% -->
<!-- %%  This file contains a tutorial introduction to domains. -->
<!-- %% -->
<P/>

<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Chapter Label="Domains">
<Heading>Domains</Heading>

<E>Domain</E> is &GAP;'s name for structured sets.
We already saw examples of domains in
Chapters&nbsp;<Ref Chap="Groups and Homomorphisms"/>
and&nbsp;<Ref Chap="Vector Spaces and Algebras"/>:
the groups <C>s8</C> and <C>a8</C> in
Section&nbsp;<Ref Sect="Permutation groups"/> are domains,
likewise the field <C>f</C> and the vector space <C>v</C> in
Section&nbsp;<Ref Sect="Vector Spaces"/> are domains.
They were constructed by functions such as
<Ref Func="Group" BookName="ref"/> and <Ref Func="GF" BookName="ref"/>,
and they could be passed as arguments to other functions such as
<Ref Func="DerivedSubgroup" BookName="ref"/> and
<Ref Func="Dimension" BookName="ref"/>.


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Domains as Sets">
<Heading>Domains as Sets</Heading>

First of all, a domain <M>D</M> is a set.
If <M>D</M> is finite then a list with the elements of this set can be
computed with the functions <Ref Func="AsList" BookName="ref"/>
and <Ref Func="AsSortedList" BookName="ref"/>.
For infinite <M>D</M>, <Ref Func="Enumerator" BookName="ref"/>
and <Ref Func="EnumeratorSorted" BookName="ref"/> may work,
but it is also possible that one gets an error message.
<P/>
Domains can be used as arguments of set functions such as
<Ref Func="Intersection" BookName="ref"/>
and <Ref Func="Union" BookName="ref"/>.
&GAP; tries to return a domain in these cases,
moreover it tries to return a domain with as much structure as possible.
For example, the intersection of two groups is (either empty or) again a
group, and &GAP; will try to return it as a group.
For <Ref Func="Union" BookName="ref"/>,
the situation is different because the union of two groups
is in general not a group.
<P/>
<Example><![CDATA[
gap> g:= Group( (1,2), (3,4) );;
gap> h:= Group( (3,4), (5,6) );;
gap> Intersection( g, h );
Group([ (3,4) ])
]]></Example>
<P/>
Two domains are regarded as equal w.r.t. the operator <Q><C>=</C></Q>
if and only if they are equal <E>as sets</E>,
regardless of the additional structure of the domains.
<P/>
<Example><![CDATA[
gap> mats:= [ [ [ 0*Z(2), Z(2)^0 ], [ Z(2)^0, 0*Z(2) ] ],
>             [ [ Z(2)^0, 0*Z(2) ], [ 0*Z(2), Z(2)^0 ] ] ];;
gap> Ring( mats ) = VectorSpace( GF(2), mats );
true
]]></Example>
<P/>
Additionally, a domain is regarded as equal to the sorted list
of its elements.
<P/>
<Example><![CDATA[
gap> g:= Group( (1,2) );;
gap> l:= AsSortedList( g );
[ (), (1,2) ]
gap> g = l;
true
gap> IsGroup( l ); IsList( g );
false
false
]]></Example>

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Algebraic Structure">
<Heading>Algebraic Structure</Heading>

The additional structure of <M>D</M> is constituted by the facts that
<M>D</M> is known to be closed under certain operations such as addition or
multiplication, and that these operations have additional properties.
For example, if <M>D</M> is a group then it is closed under multiplication
(<M>D \times D \rightarrow D</M>, <M>(g,h) \mapsto g * h</M>),
under taking inverses (<M>D \rightarrow D</M>, <M>g \mapsto g^{-1}</M>)
and under taking the identity <M>g</M><C>^0</C> of each element <M>g</M>
in <M>D</M>;
additionally, the multiplication in <M>D</M> is associative.
<P/>
The same set of elements can carry different algebraic structures.
For example, a semigroup is defined as being closed under an associative
multiplication, so each group is also a semigroup.
Likewise, a monoid is defined as a semigroup <M>D</M> in which the identity
<M>g</M><C>^0</C> is defined for every element <M>g</M>,
so each group is a monoid,
and each monoid is a semigroup.
<P/>
Other examples of domains are vector spaces, which are defined as
additive groups that are closed under (left) multiplication with elements
in a certain domain of scalars.
Also conjugacy classes in a group <M>D</M> are domains,
they are closed under the conjugation action of <M>D</M>.

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Notions of Generation">
<Heading>Notions of Generation</Heading>

<Index Key="GeneratorsOfSomething"><C>GeneratorsOfSomething</C></Index>
We have seen that a domain is closed under certain operations.
Usually a domain is constructed as the closure of some elements under
these operations.
In this situation, we say that the elements <E>generate</E> the domain.
<P/>
For example, a list of matrices of the same shape over a common field
can be used to generate an additive group or a vector space over a
suitable field; if the matrices are square then we can also use the
matrices as generators of a semigroup, a ring, or an algebra. We
illustrate some of these possibilities:
<P/>
<Example><![CDATA[
gap> mats:= [ [ [ 0*Z(2), Z(2)^0 ],
>               [ Z(2)^0, 0*Z(2) ] ], 
>             [ [ Z(2)^0, 0*Z(2) ],
>               [ 0*Z(2), Z(2)^0 ] ] ];;
gap> Size( AdditiveMagma( mats ) );
4
gap> Size( VectorSpace( GF(8), mats ) );
64
gap> Size( Algebra( GF(2), mats ) );    
4
gap> Size( Group( mats ) );         
2
]]></Example>
Each combination of operations under which a domain could be closed
gives a notion of generation.
So each group has group generators, and since it is a monoid,
one can also ask for monoid generators of a group.
<P/>
Note that one cannot simply ask for <Q>the generators of a domain</Q>,
it is always necessary to specify what notion of generation is meant.
Access to the different generators is provided by functions with
names of the form <C>GeneratorsOfSomething</C>.
For example, <Ref Func="GeneratorsOfGroup" BookName="ref"/> denotes
group generators,
<Ref Func="GeneratorsOfMonoid" BookName="ref"/> denotes monoid generators,
and so on.
The result of <Ref Func="GeneratorsOfVectorSpace" BookName="ref"/> is
of course to be understood
relative to the field of scalars of the vector space in question.
<P/>
<Example><![CDATA[
gap> GeneratorsOfVectorSpace( GF(4)^2 );
[ [ Z(2)^0, 0*Z(2) ], [ 0*Z(2), Z(2)^0 ] ]
gap> v:= AsVectorSpace( GF(2), GF(4)^2 );;
gap> GeneratorsOfVectorSpace( v );
[ [ Z(2)^0, 0*Z(2) ], [ 0*Z(2), Z(2)^0 ], [ Z(2^2), 0*Z(2) ], 
  [ 0*Z(2), Z(2^2) ] ]
]]></Example>

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Domain Constructors">
<Heading>Domain Constructors</Heading>

<Index Key="Something"><C>Something</C></Index>
A group can be constructed from a list of group generators <A>gens</A> by
<C>Group( <A>gens</A> )</C>,
likewise one can construct rings and algebras with the functions
<Ref Func="Ring" BookName="ref"/>
and <Ref Func="Algebra" BookName="ref"/>.
<P/>
Note that it is not always or completely checked that <A>gens</A> is in
fact a valid list of group generators, for example whether the
elements of <A>gens</A> can be multiplied or whether they are invertible.
This means that &GAP; trusts you, at least to some extent, that the
desired domain <C>Something( <A>gens</A> )</C> does exist.

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Forming Closures of Domains">
<Heading>Forming Closures of Domains</Heading>

<Index Key="ClosureSomething"><C>ClosureSomething</C></Index>
Besides constructing domains from generators, one can also form the
closure of a given domain with an element or another domain.
There are different notions of closure, one has to specify one
according to the desired result and the structure of the given domain.
The functions to compute closures have names such as
<C>ClosureSomething</C>.
For example, if <A>D</A> is a group and one wants to construct the group
generated by <A>D</A> and an element <A>g</A> then one can use
<C>ClosureGroup( <A>D</A>, <A>g</A> )</C>.

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Changing the Structure">
<Heading>Changing the Structure</Heading>

<Index Key="AsSomething"><C>AsSomething</C></Index>
The same set of elements can have different algebraic structures.
For example, it may happen that a monoid <M>M</M> does in fact contain
the inverses of all of its elements, and thus <M>M</M> is equal to the group
formed by the elements of <M>M</M>.
<P/>
<Example><![CDATA[
gap> m:= Monoid( mats );;
gap> m = Group( mats );
true
gap> IsGroup( m );
false
]]></Example>
<P/>
The last result in the above example may be surprising.
But the monoid <C>m</C> is not regarded as a group in &GAP;,
and moreover there is no way to turn <C>m</C> into a group.
Let us formulate this as a rule:
<P/>
<E>The set of operations under which the domain is closed is fixed
in the construction of a domain, and cannot be changed later.</E>
<P/>
(Contrary to this, a domain <E>can</E> acquire knowledge about properties
such as whether the multiplication is associative or commutative.)
<P/>
If one needs a domain with a different structure than the given one,
one can construct a new domain with the required structure.
The functions that do these constructions have names such as
<C>AsSomething</C>, they return a domain that has the same elements as the
argument in question but the structure <C>Something</C>.
In the above situation, one can use <Ref Func="AsGroup" BookName="ref"/>.
<P/>
<Example><![CDATA[
gap> g:= AsGroup( m );;
gap> m = g;
true
gap> IsGroup( g );
true
]]></Example>
<P/>
If it is impossible to construct the desired domain, the <C>AsSomething</C>
functions return <K>fail</K>.
<P/>
<Example><![CDATA[
gap> AsVectorSpace( GF(4), GF(2)^2 );
fail
]]></Example>
<P/>
The functions <Ref Func="AsList" BookName="ref"/> and
<Ref Func="AsSortedList" BookName="ref"/> mentioned above do not return
domains, but they fit into the general pattern in the sense that they
forget all the structure of the argument, including the fact that it is
a domain, and return a list with the same elements as the argument has.

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Subdomains">
<Heading>Subdomains</Heading>

<Index Key="Subsomething"><C>Subsomething</C></Index>
<Index Key="SubsomethingNC"><C>SubsomethingNC</C></Index>
It is possible to construct a domain as a subset of an existing domain.
The respective functions have names such as <C>Subsomething</C>,
they return domains with the structure <C>Something</C>.
(Note that the second <C>s</C> in <C>Subsomething</C> is not capitalized.)
For example, if one wants to deal with the subgroup of the domain <A>D</A>
that is generated by the elements in the list <A>gens</A>,
one can use <C>Subgroup( <A>D</A>, <A>gens</A> )</C>.
It is not required that <A>D</A> is itself a group,
only that the group generated by <A>gens</A> must be a subset of <A>D</A>.
<P/>
The superset of a domain <A>S</A> that was constructed by a
<C>Subsomething</C>
function can be accessed as <C>Parent( <A>S</A> )</C>.
<P/>
<Example><![CDATA[
gap> g:= SymmetricGroup( 5 );;
gap> gens:= [ (1,2), (1,2,3,4) ];;
gap> s:= Subgroup( g, gens );;
gap> h:= Group( gens );;
gap> s = h;
true
gap> Parent( s ) = g;
true
]]></Example>
<P/>
Many functions return subdomains of their arguments, for example
the result of <C>SylowSubgroup( <A>G</A> )</C> is a group with parent group
<A>G</A>.
<P/>
If you are sure that the domain <C>Something( <A>gens</A> )</C> is contained
in the
domain <A>D</A> then you can also call
<C>SubsomethingNC( <A>D</A>, <A>gens</A> )</C> instead
of <C>Subsomething( <A>D</A>, <A>gens</A> )</C>.
The <C>NC</C> stands for <Q>no check</Q>,
and the functions whose names end with
<C>NC</C> omit the check of containment.

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Further Information about Domains">
<Heading>Further Information about Domains</Heading>

More information about domains can be found in
Chapter&nbsp;<Ref Sect="Domains" BookName="ref"/>. Many other other chapters deal with specific
types of domain such as groups, vector spaces or algebras.

</Section>
</Chapter>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<!-- %% -->
<!-- %E -->

