% generated by GAPDoc2LaTeX from XML source (Frank Luebeck)
\documentclass[11pt]{report}
\usepackage{a4wide}
\sloppy
\pagestyle{myheadings}
\usepackage{amssymb}
\usepackage[latin1]{inputenc}
\usepackage{makeidx}
\makeindex
\usepackage{graphicx}
\usepackage{color}
\definecolor{DarkOlive}{rgb}{0.1047,0.2412,0.0064}
\definecolor{FireBrick}{rgb}{0.5812,0.0074,0.0083}
\definecolor{RoyalBlue}{rgb}{0.0236,0.0894,0.6179}
\definecolor{RoyalGreen}{rgb}{0.0236,0.6179,0.0894}
\definecolor{RoyalRed}{rgb}{0.6179,0.0236,0.0894}
\definecolor{LightBlue}{rgb}{0.8544,0.9511,1.0000}
\definecolor{Black}{rgb}{0.0,0.0,0.0}
\definecolor{FuncColor}{rgb}{1.0,0.0,0.0}
%% strange name because of pdflatex bug:
\definecolor{Chapter }{rgb}{0.0,0.0,1.0}

\usepackage{fancyvrb}

\usepackage{pslatex}

\usepackage[
        a4paper=true,bookmarks=false,pdftitle={Written with GAPDoc},
        colorlinks=true,backref=page,breaklinks=true,linkcolor=RoyalBlue,
        citecolor=RoyalGreen,filecolor=RoyalRed,
        urlcolor=RoyalRed,pagecolor=RoyalBlue]{hyperref}

% write page numbers to a .pnr log file for online help
\newwrite\pagenrlog
\immediate\openout\pagenrlog =\jobname.pnr
\immediate\write\pagenrlog{PAGENRS := [}
\newcommand{\logpage}[1]{\protect\write\pagenrlog{#1, \thepage,}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\F}{\mathbb{F}}

\newcommand{\GAP}{\textsf{GAP}}

\newsavebox{\backslashbox}
\sbox{\backslashbox}{\texttt{\symbol{92}}}
\newcommand{\bs}{\usebox{\backslashbox}}

\begin{document}

\logpage{[ 0, 0, 0 ]}
\begin{titlepage}
\begin{center}{\Huge \textbf{Automata}}\\[1cm]
\markright{\scriptsize \mbox{}\hfill Automata \hfill\mbox{}}
{( Version 1.09 ) }\\[1cm]
\mbox{}\\[2cm]
{\large \textbf{ Manuel Delgado   }}\\
{\large \textbf{ Steve Linton   }}\\
{\large \textbf{ José João Morais  }}\\
\end{center}\vfill

\mbox{}\\
{\mbox{}\\
\small \noindent \textbf{ Manuel Delgado   } --- Email: \href{mailto://mdelgado@fc.up.pt}{\texttt{mdelgado@fc.up.pt}}\\
 --- Homepage: \href{http://www.fc.up.pt/cmup/mdelgado}{\texttt{http://www.fc.up.pt/cmup/mdelgado}}}\\
{\mbox{}\\
\small \noindent \textbf{ Steve Linton   } --- Email: \href{mailto://sal@dcs.st-and.ac.uk}{\texttt{sal@dcs.st-and.ac.uk}}\\
 --- Homepage: \href{http://www.dcs.st-and.ac.uk/~sal/}{\texttt{http://www.dcs.st-and.ac.uk/\~{}sal/}}}\\
{\mbox{}\\
\small \noindent \textbf{ José João Morais  } --- Email: \href{mailto://josejoao@fc.up.pt}{\texttt{josejoao@fc.up.pt}}}\\
\end{titlepage}

\newpage\setcounter{page}{2}
{\small 
\section*{Copyright}
\logpage{[ 0, 0, 1 ]}
 {\copyright} 2004 by Manuel Delgado, Steve Linton and José Morais 

 We adopt the copyright regulations of \textsf{GAP} as detailed in the copyright notice in the \textsf{GAP} manual. }\\[1cm]
{\small 
\section*{Acknowledgements}
\logpage{[ 0, 0, 3 ]}
 The first author wishes to acknowledge Cyril Nicaud and Paulo Varandas for
their help in programming some functions of the very first version of this
package. He wishes also to acknowledge useful discussions and comments by
Cyril Nicaud, Vítor H. Fernandes, Jean-Eric Pin and Jorge Almeida. 

 The first author also acknowledges support of FCT through CMUP and the FCT and
POCTI Project POCTI/32817/MAT/2000 which is funded in cooperation with the
European Community Fund FEDER. 

 The third author acknowledges financial support of FCT and the POCTI program
through a scholarship given by Centro de Matemática da Universidade do Porto. 

 The authors would like to thank Mark Kambites
(http://www.theory.informatik.uni-kassel.de/~kambites/) for his contribution
in finding bugs and making suggestions for the improvement of this package. }\\[1cm]
{\small 
\section*{Colophon}
\logpage{[ 0, 0, 2 ]}
 This work started in 1998, when the first author was in the LIAFA at the
University of Paris 7, in a post-doc. Encouraged by J. E. Pin, he began the
implementation in \textsf{GAP}3 of an algorithm obtained some time before to answer a question from the
realm of Finite Semigroups proposed by J. Almeida. It is now part of a
separate package: \texttt{finsemi}. 

 The first version of this package on automata was prepared by the first author
who gave it the form of a \textsf{GAP} share package. In a second version, prepared by the first and third authors,
many functions have been added and the performance of many of the existing
ones has been improved. Further important improvements, specially concerning
performance, have been achieved when the second author joined the group. Bug
reports, suggestions and comments are, of course, welcome. Please contact any
of the authors to this effect. Our e-mail addresses are \href{mailto://mdelgado@fc.up.pt}{\texttt{mdelgado@fc.up.pt}} or \href{mailto://sal@dcs.st-and.ac.uk}{\texttt{sal@dcs.st-and.ac.uk}} or \href{mailto://josejoao@fc.up.pt}{\texttt{josejoao@fc.up.pt}}. }\\[1cm]
\newpage

\def\contentsname{Contents\logpage{[ 0, 0, 4 ]}}

\tableofcontents
\newpage

   
\chapter{\textcolor{Chapter }{ Introduction }}\logpage{[ 1, 0, 0 ]}
{
  In many situations an automaton is conveniently described through a diagram
like the following 

  \begin{figure}[htbp] \begin{center} \leavevmode \includegraphics[bb=0 0 132
279]{aut1} \end{center} \label{fig:aut1} \end{figure}   

 This diagram describes a (deterministic) automaton with $ 3 $ states (the elements of the set $ \{1,2,3\}). $ The arrow pointing to the state $ 1 $ indicates that $ 1 $ is the initial state and the two circles around state $ 3 $ indicate that $ 3 $ is a final or accepting state. The set $ \{a,b\} $ is the \emph{alphabet} of the automaton; its elements are called \emph{letters} and are the labels of the edges of the diagram. The words $ a $ , $ ab^2 $ , $ b^5a^3b $ are examples of words recognized by the automaton since they are labels of
paths from the initial to the final state. 

 The set of words recognized by an automaton is called the \emph{language} of the automaton. It is a rational language and may be represented through a
rational expression. For instance, 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  (aUb)(a(aUb)Ub(aUb))*
\end{Verbatim}
 is a rational expression representing the language of the above automaton. 

 Kleene's Theorem states that a language is rational if and only if it is the
language of a finite automaton. Both directions of Kleene's Theorem can be
proved constructively, and these algorithms, to go from an automaton to a
rational expression and \emph{vice-versa}, are implemented in this package. 

 Of course, one has to pay attention to the size of the output produced. When
producing a deterministic automaton equivalent to a given rational expression
one can obtain an optimal solution (the minimal automaton) using standard
algorithms \cite{AHU:74}. 

 When producing a rational expression for the language of an automaton, and
taking into account some reasonable measure for the size of a rational
expression, to determine a minimal one is apparently computationally
difficult. We use here some heuristic methods (to be published elsewhere)
which in practice lead to very reasonable results. 

 The development of this work has benefited from the existence of AMoRE \cite{AMORE:95}, a package written in \texttt{C} to handle Automata, Monoids and Regular Expressions. In fact, its manual has
been very useful and some of the algorithms implemented here are those
implemented in AMoRE. In this package, unlike what happened with AMoRE, we do
not have to worry about the monoid part in order to make it useful to
semigroup theorists, since monoids are already implemented in \textsf{GAP} and we may take advantage of this fact. We just need a function to compute the
transition semigroup of an automaton. 

 

 The parts of this package that have not so directly to do with automata or
rational expressions are put into appendices in this manual. Some words about
these appendices follow. 

 Using the external program Graphviz \cite{KoutsofiosNorth:2002} to graph visualization, one can visualize automata. This very convenient tool
presently works easily under LINUX. 

 Given a finitely generated subgroup of the free group it is possible to
compute a flower automaton and perform Stallings foldings over it in order to
obtain an inverse automaton corresponding to the given subgroup. 

 }

  
\chapter{\textcolor{Chapter }{Finite Automata}}\logpage{[ 2, 0, 0 ]}
{
 This chapter describes the representations used in this package for finite
automata and some functions to determine information about them. 

 We have to remark that the states of an automaton are always named $1,2,3,\ldots;$ the alphabet may be given by the user. By default it is $\{a,b,c,\ldots\}$ (or $\{a_1,a_2,a_3,\ldots\}$ in the case of alphabets with more than $7$ letters). 

 The transition function of an automaton with $q$ states over an alphabet with $ n$ letters is represented by a (not necessarily dense) $n\times q$ matrix. Each row of the matrix describes the action of the corresponding
letter on the states. In the case of a \emph{deterministic automaton} (DFA) the entries of the matrix are non-negative integers. When all entries of
the transition table are positive integers, the automaton is said to be \emph{dense} or \emph{complete}.  In the case of a \emph{non deterministic automaton} (NFA) the entries of the matrix may be lists of non-negative integers. \emph{Automata with $\epsilon$-transitions} are also allowed: the last letter of the alphabet is assumed to be $\epsilon$ and is represented by @. 
\section{\textcolor{Chapter }{Automata generation}}\logpage{[ 2, 1, 0 ]}
{
  The way to create an automaton in \textsf{GAP} is the following 

\subsection{\textcolor{Chapter }{Automaton}}
\logpage{[ 2, 1, 1 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{Automaton( Type, Size, Alphabet, TransitionTable, Initial, Accepting )\index{Automaton@\texttt{Automaton}}
\label{Automaton}
}\hfill{\scriptsize (function)}}\\


  \texttt{Type} may be \texttt{"det"}, \texttt{"nondet"} or \texttt{"epsilon"} according to whether the automaton is deterministic, non deterministic or an
automaton with $\epsilon$-transitions. \texttt{Size} is a positive integer representing the number of states of the automaton. \texttt{Alphabet} is the number of letters of the alphabet or a list with the letters of the
ordered alphabet. \texttt{TransitionTable} is the transition matrix. The entries are non-negative integers not greater
than the size of the automaton. In the case of non deterministic automata,
lists of non-negative integers not greater than the size of the automaton are
also allowed. \texttt{Initial} and \texttt{Accepting} are, respectively, the lists of initial and accepting states. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  
  gap> aut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,4]],[1],[4]);
  < deterministic automaton on 2 letters with 4 states >
  gap> Display(aut);
     |  1  2  3  4
  -----------------
   a |  3     3  4
   b |  3  4     4
  Initial state:   [ 1 ]
  Accepting state: [ 4 ]
  
\end{Verbatim}
 The alphabet of the automaton may be specified: 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> aut:=Automaton("det",4,"01",[[3,,3,4],[3,4,0,4]],[1],[4]);
  < deterministic automaton on 2 letters with 4 states >
  gap> Display(aut);
     |  1  2  3  4
  -----------------
   0 |  3     3  4
   1 |  3  4     4
  Initial state:   [ 1 ]
  Accepting state: [ 4 ]
\end{Verbatim}
 Instead of leaving a hole in the transition matrix, we may write a \texttt{0} to mean that no transition is present. Non deterministic automata may be given
the same way. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> ndaut:=Automaton("nondet",4,2,[[3,[1,2],3,0],[3,4,0,[2,3]]],[1],[4]);
  < non deterministic automaton on 2 letters with 4 states >
  gap> Display(ndaut);
     |  1       2          3       4
  -----------------------------------------
   a | [ 3 ]   [ 1, 2 ]   [ 3 ]
   b | [ 3 ]   [ 4 ]              [ 2, 3 ]
  Initial state:   [ 1 ]
  Accepting state: [ 4 ]
\end{Verbatim}
 Also in the same way can be given $\epsilon$-automata. The letter $\epsilon$ is written \texttt{@} instead. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> x:=Automaton("epsilon",3,"01@",[[,[2],[3]],[[1,3],,[1]],[[1],[2],
  > [2]]],[2],[2,3]);
  < epsilon automaton on 3 letters with 3 states >
  gap> Display(x);
     |  1          2       3
  ------------------------------
   0 |            [ 2 ]   [ 3 ]
   1 | [ 1, 3 ]           [ 1 ]
   @ | [ 1 ]      [ 2 ]   [ 2 ]
  Initial state:    [ 2 ]
  Accepting states: [ 2, 3 ]
\end{Verbatim}
 Bigger automata are displayed in another form: 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> aut:=Automaton("det",16,2,[[4,0,0,6,3,1,4,8,7,4,3,0,6,1,6,0],
  > [3,4,0,0,6,1,0,6,1,6,1,6,6,4,8,7,4,5]],[1],[4]);
  < deterministic automaton on 2 letters with 16 states >
  gap> Display(aut);
  1    a   4
  1    b   3
  2    b   4
      ... some more lines
  15   a   6
  15   b   8
  16   b   7
  Initial state:   [ 1 ]
  Accepting state: [ 4 ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{IsAutomaton}}
\logpage{[ 2, 1, 2 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{IsAutomaton( O )\index{IsAutomaton@\texttt{IsAutomaton}}
\label{IsAutomaton}
}\hfill{\scriptsize (function)}}\\


 In the presence of an object \mbox{\texttt{O}}, one may want to test whether \texttt{O} is an automaton. This may be done using the function \texttt{IsAutomaton}. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> x:=Automaton("det",3,2,[ [ 0, 2, 0 ], [ 0, 1, 0 ] ],[ 3 ],[ 2 ]);;
  gap> IsAutomaton(x);
  true
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{IsDeterministicAutomaton}}
\logpage{[ 2, 1, 3 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{IsDeterministicAutomaton( aut )\index{IsDeterministicAutomaton@\texttt{IsDeterministicAutomaton}}
\label{IsDeterministicAutomaton}
}\hfill{\scriptsize (function)}}\\


 Returns \texttt{true} when \texttt{aut} is a deterministic automaton and \texttt{false} otherwise. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> x:=Automaton("det",3,2,[ [ 0, 2, 0 ], [ 0, 1, 0 ] ],[ 3 ],[ 2 ]);;
  gap> IsDeterministicAutomaton(x);
  true
\end{Verbatim}
 }

  

\subsection{\textcolor{Chapter }{IsNonDeterministicAutomaton}}
\logpage{[ 2, 1, 4 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{IsNonDeterministicAutomaton( aut )\index{IsNonDeterministicAutomaton@\texttt{IsNonDeterministicAutomaton}}
\label{IsNonDeterministicAutomaton}
}\hfill{\scriptsize (function)}}\\


 Returns \texttt{true} when \texttt{aut} is a non deterministic automaton and \texttt{false} otherwise. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> y:=Automaton("nondet",3,2,[[,[1,3],],[,[2,3],[1,3]]],[1,2],[1,3]);;
  gap> IsNonDeterministicAutomaton(y);
  true
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{IsEpsilonAutomaton}}
\logpage{[ 2, 1, 5 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{IsEpsilonAutomaton( aut )\index{IsEpsilonAutomaton@\texttt{IsEpsilonAutomaton}}
\label{IsEpsilonAutomaton}
}\hfill{\scriptsize (function)}}\\


 Returns \texttt{true} when \texttt{aut} is an $\epsilon$-automaton and \texttt{false} otherwise. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> z:=Automaton("epsilon",2,2,[[[1,2],],[[2],[1]]],[1,2],[1,2]);;
  gap> IsEpsilonAutomaton(z);
  true
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{String}}
\logpage{[ 2, 1, 6 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{String( aut )\index{String@\texttt{String}}
\label{String}
}\hfill{\scriptsize (function)}}\\


 The way \textsf{GAP} displays an automaton is quite natural, but when one wants to do small
changes, for example using \emph{copy/paste}, the use of the function \texttt{String} (possibly followed by \texttt{Print}) may be usefull. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> x:=Automaton("det",3,2,[ [ 0, 2, 0 ], [ 0, 1, 0 ] ],[ 3 ],[ 2 ]);;
  gap> String(x);
  "Automaton(\"det\",3,2,[ [ 0, 2, 0 ], [ 0, 1, 0 ] ],[ 3 ],[ 2 ]);;"
  gap> Print(String(x));
  Automaton("det",3,2,[ [ 0, 2, 0 ], [ 0, 1, 0 ] ],[ 3 ],[ 2 ]);;
\end{Verbatim}
 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> z:=Automaton("epsilon",2,2,[[[1,2],],[[2],[1]]],[1,2],[1,2]);;
  gap> Print(String(z));
  Automaton("epsilon",2,2,[[[1,2],],[[2],[1]]],[1,2],[1,2]);;
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{RandomAutomaton}}
\logpage{[ 2, 1, 7 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{RandomAutomaton( Type, Size, Alphabet )\index{RandomAutomaton@\texttt{RandomAutomaton}}
\label{RandomAutomaton}
}\hfill{\scriptsize (function)}}\\


 Given the \mbox{\texttt{Type}}, the \mbox{\texttt{Size}} (i.e. the number of states) and the \mbox{\texttt{Alphabet}} (a positive integer or a list), returns a pseudo random automaton with these
parameters. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> RandomAutomaton("det",5,"ac");
  < deterministic automaton on 2 letters with 5 states >
  gap> Display(last);
     |  1  2  3  4  5
  --------------------
   a |     2  3
   c |  2  3
  Initial state:    [ 4 ]
  Accepting states: [ 3, 4 ]
  
  gap> RandomAutomaton("nondet",3,["a","b","c"]);
  < non deterministic automaton on 3 letters with 3 states >
  
  gap> RandomAutomaton("epsilon",2,"abc");
  < epsilon automaton on 4 letters with 2 states >
  
  gap> RandomAutomaton("epsilon",2,2);
  < epsilon automaton on 3 letters with 2 states >
  gap> Display(last);
     |  1          2
  ----------------------
   a | [ 1, 2 ]
   b | [ 2 ]      [ 1 ]
   @ | [ 1, 2 ]
  Initial state:    [ 2 ]
  Accepting states: [ 1, 2 ]
  
  gap> a:=RandomTransformation(3);;
  gap> b:=RandomTransformation(3);;
  gap> aut:=RandomAutomaton("det",4,[a,b]);
  < deterministic automaton on 2 letters with 4 states >
\end{Verbatim}
 }

 }

 
\section{\textcolor{Chapter }{Automata internals}}\logpage{[ 2, 2, 0 ]}
{
 In this section we describe the functions used to access the internals of an
automaton. 

\subsection{\textcolor{Chapter }{AlphabetOfAutomaton}}
\logpage{[ 2, 2, 1 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{AlphabetOfAutomaton( aut )\index{AlphabetOfAutomaton@\texttt{AlphabetOfAutomaton}}
\label{AlphabetOfAutomaton}
}\hfill{\scriptsize (function)}}\\


 Returns the alphabet of automaton \texttt{aut}. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> aut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;
  gap> AlphabetOfAutomaton(aut);
  "ab"
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{AlphabetOfAutomatonAsList}}
\logpage{[ 2, 2, 2 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{AlphabetOfAutomatonAsList( aut )\index{AlphabetOfAutomatonAsList@\texttt{AlphabetOfAutomatonAsList}}
\label{AlphabetOfAutomatonAsList}
}\hfill{\scriptsize (function)}}\\


 Returns the alphabet of automaton \texttt{aut} always as a list. If the alphabet of the automaton is an integer less than 27
it returns the list \texttt{"abcd...."}, otherwise returns \texttt{[ "a1", "a2", "a3", "a4", ... ]}. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> a:=RandomAutomaton("det",5,"cat");
  < deterministic automaton on 3 letters with 5 states >
  gap> AlphabetOfAutomaton(a);
  "cat"
  gap> AlphabetOfAutomatonAsList(a);
  "cat"
  gap> a:=RandomAutomaton("det",5,20);
  < deterministic automaton on 20 letters with 5 states >
  gap> AlphabetOfAutomaton(a);
  20
  gap> AlphabetOfAutomatonAsList(a);
  "abcdefghijklmnopqrst"
  gap> a:=RandomAutomaton("det",5,30);
  < deterministic automaton on 30 letters with 5 states >
  gap> AlphabetOfAutomaton(a);
  30
  gap> AlphabetOfAutomatonAsList(a);
  [ "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10", "a11", 
    "a12", "a13", "a14", "a15", "a16", "a17", "a18", "a19", "a20", "a21",
    "a22", "a23", "a24", "a25", "a26", "a27", "a28", "a29", "a30" ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{TransitionMatrixOfAutomaton}}
\logpage{[ 2, 2, 3 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{TransitionMatrixOfAutomaton( aut )\index{TransitionMatrixOfAutomaton@\texttt{TransitionMatrixOfAutomaton}}
\label{TransitionMatrixOfAutomaton}
}\hfill{\scriptsize (function)}}\\


 Returns the transition matrix of automaton \texttt{aut}. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> aut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;
  gap> TransitionMatrixOfAutomaton(aut);
  [ [ 3, 0, 3, 4 ], [ 3, 4, 0, 0 ] ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{InitialStatesOfAutomaton}}
\logpage{[ 2, 2, 4 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{InitialStatesOfAutomaton( aut )\index{InitialStatesOfAutomaton@\texttt{InitialStatesOfAutomaton}}
\label{InitialStatesOfAutomaton}
}\hfill{\scriptsize (function)}}\\


 Returns the initial states of automaton \texttt{aut}. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> aut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;
  gap> InitialStatesOfAutomaton(aut);
  [ 1 ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{SetInitialStatesOfAutomaton}}
\logpage{[ 2, 2, 5 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{SetInitialStatesOfAutomaton( aut, I )\index{SetInitialStatesOfAutomaton@\texttt{SetInitialStatesOfAutomaton}}
\label{SetInitialStatesOfAutomaton}
}\hfill{\scriptsize (function)}}\\


 Sets the initial states of automaton \texttt{aut}. \texttt{I} may be a positive integer or a list of positive integers. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> aut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;
  gap> SetInitialStatesOfAutomaton(aut,4);
  gap> InitialStatesOfAutomaton(a);
  [ 4 ]
  gap> SetInitialStatesOfAutomaton(aut,[2,3]);
  gap> InitialStatesOfAutomaton(aut);
  [ 2, 3 ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{FinalStatesOfAutomaton}}
\logpage{[ 2, 2, 6 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{FinalStatesOfAutomaton( aut )\index{FinalStatesOfAutomaton@\texttt{FinalStatesOfAutomaton}}
\label{FinalStatesOfAutomaton}
}\hfill{\scriptsize (function)}}\\


 Returns the final states of automaton \texttt{aut}. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> aut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;
  gap> FinalStatesOfAutomaton(aut);
  [ 4 ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{SetFinalStatesOfAutomaton}}
\logpage{[ 2, 2, 7 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{SetFinalStatesOfAutomaton( aut, F )\index{SetFinalStatesOfAutomaton@\texttt{SetFinalStatesOfAutomaton}}
\label{SetFinalStatesOfAutomaton}
}\hfill{\scriptsize (function)}}\\


 Sets the final states of automaton \texttt{aut}. \texttt{F} may be a positive integer or a list of positive integers. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> aut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;
  gap> FinalStatesOfAutomaton(aut);
  [ 4 ]
  gap> SetFinalStatesOfAutomaton(aut,2);
  gap> FinalStatesOfAutomaton(aut);
  [ 2 ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{NumberStatesOfAutomaton}}
\logpage{[ 2, 2, 8 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{NumberStatesOfAutomaton( aut )\index{NumberStatesOfAutomaton@\texttt{NumberStatesOfAutomaton}}
\label{NumberStatesOfAutomaton}
}\hfill{\scriptsize (function)}}\\


 Returns the number of states of automaton \texttt{aut}. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> aut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;
  gap> NumberStatesOfAutomaton(aut);
  4
\end{Verbatim}
 }

 }

 
\section{\textcolor{Chapter }{Comparison of automata}}\logpage{[ 2, 3, 0 ]}
{
 Although there is no standard way to compare automata it is usefull to be able
to do some kind of comparison. Doing so, one can consider sets of automata. We
just compare the strings of the automata. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> x:=Automaton("det",3,2,[ [ 0, 2, 0 ], [ 0, 1, 0 ] ],[ 3 ],[ 2 ]);;
  gap> y:=Automaton("det",3,2,[ [ 2, 0, 0 ], [ 1, 3, 0 ] ],[ 3 ],[ 2, 3 ]);;
  gap> x=y;
  false
  gap> Size(Set([y,x,x]));
  2
\end{Verbatim}
 }

 
\section{\textcolor{Chapter }{Tests involving automata}}\logpage{[ 2, 4, 0 ]}
{
 This section describes some useful tests involving automata. 

\subsection{\textcolor{Chapter }{IsDenseAutomaton}}
\logpage{[ 2, 4, 1 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{IsDenseAutomaton( aut )\index{IsDenseAutomaton@\texttt{IsDenseAutomaton}}
\label{IsDenseAutomaton}
}\hfill{\scriptsize (function)}}\\


 Tests whether a deterministic automaton \texttt{aut} is complete. (See also \texttt{NullCompletionAutomaton} (\ref{NullCompletionAutomaton}).) 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> aut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;
  gap> IsDenseAutomaton(aut);                                 
  false
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{IsRecognizedByAutomaton}}
\logpage{[ 2, 4, 2 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{IsRecognizedByAutomaton( A, w )\index{IsRecognizedByAutomaton@\texttt{IsRecognizedByAutomaton}}
\label{IsRecognizedByAutomaton}
}\hfill{\scriptsize (function)}}\\


 The argments are: an automaton \mbox{\texttt{A}} and a string (i.e. a word) \mbox{\texttt{w}} in the alphabet of the automaton. Returns \texttt{true} if the word is recognized by the automaton and \texttt{false} otherwise. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> aut:=Automaton("det",3,2,[[1,2,1],[2,1,3]],[1],[2]);;
  gap> IsRecognizedByAutomaton(aut,"bbb");
  true
  
  gap> aut:=Automaton("det",3,"01",[[1,2,1],[2,1,3]],[1],[2]);;
  gap> IsRecognizedByAutomaton(aut,"111");
  true
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{IsPermutationAutomaton}}
\logpage{[ 2, 4, 3 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{IsPermutationAutomaton( aut )\index{IsPermutationAutomaton@\texttt{IsPermutationAutomaton}}
\label{IsPermutationAutomaton}
}\hfill{\scriptsize (function)}}\\


 The argument is a deterministic automaton. Returns \texttt{true} when each letter of the alphabet induces a permutation on the vertices and \texttt{false} otherwise. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> x:=Automaton("det",3,2,[ [ 1, 2, 3 ], [ 1, 2, 3 ] ],[ 1 ],[ 2, 3 ]);;
  gap> IsPermutationAutomaton(x);
  true
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{IsInverseAutomaton}}
\logpage{[ 2, 4, 4 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{IsInverseAutomaton( aut )\index{IsInverseAutomaton@\texttt{IsInverseAutomaton}}
\label{IsInverseAutomaton}
}\hfill{\scriptsize (function)}}\\


 The argument is a deterministic automaton. Returns \texttt{true} when each letter of the alphabet induces an injective partial function on the
vertices and \texttt{false} otherwise. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> x:=Automaton("det",3,2,[ [ 0, 1, 3 ], [ 0, 1, 2 ] ],[ 2 ],[ 1 ]);;
  gap> IsInverseAutomaton(x);
  true
\end{Verbatim}
 Frequently an inverse automaton is thought as if the inverse edges (labeled by
formal inverses of the letters of the alphabet) were present, although they
are usually not explicited. They can be made explicit using the function \texttt{AddInverseEdgesToInverseAutomaton} }

 

\subsection{\textcolor{Chapter }{AddInverseEdgesToInverseAutomaton}}
\logpage{[ 2, 4, 5 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{AddInverseEdgesToInverseAutomaton( aut )\index{AddInverseEdgesToInverseAutomaton@\texttt{AddInverseEdgesToInverseAutomaton}}
\label{AddInverseEdgesToInverseAutomaton}
}\hfill{\scriptsize (function)}}\\


 The argument is an inverse automaton over the alphabet $\{a,b,c,\ldots\}$. Returns an automaton with the inverse edges added. (The formal inverse of a
letter is represented by the corresponding capital letter.) 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> x:=Automaton("det",3,2,[[ 0, 1, 3 ],[ 0, 1, 2 ]],[ 2 ],[ 1 ]);;Display(x);
     |  1  2  3
  --------------
   a |     1  3
   b |     1  2
  Initial state:   [ 2 ]
  Accepting state: [ 1 ]
  gap> AddInverseEdgesToInverseAutomaton(x);Display(x);
     |  1  2  3
  --------------
   a |     1  3
   b |     1  2
   A |  2     3
   B |  2  3
  Initial state:   [ 2 ]
  Accepting state: [ 1 ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{IsReversibleAutomaton}}
\logpage{[ 2, 4, 6 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{IsReversibleAutomaton( aut )\index{IsReversibleAutomaton@\texttt{IsReversibleAutomaton}}
\label{IsReversibleAutomaton}
}\hfill{\scriptsize (function)}}\\


 The argument is a deterministic automaton. Returns \texttt{true} when \mbox{\texttt{aut}} is a reversible automaton, i.e. the automaton obtained by reversing all edges
and switching the initial and final states (see also \texttt{ReversedAutomaton} (\ref{ReversedAutomaton})) is deterministic. Returns \texttt{false} otherwise. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> x:=Automaton("det",3,2,[ [ 0, 1, 2 ], [ 0, 1, 3 ] ],[ 2 ],[ 2 ]);;
  gap> IsReversibleAutomaton(x);
  true
\end{Verbatim}
 }

 }

 
\section{\textcolor{Chapter }{Basic operations}}\logpage{[ 2, 5, 0 ]}
{
 

\subsection{\textcolor{Chapter }{CopyAutomaton}}
\logpage{[ 2, 5, 1 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{CopyAutomaton( aut )\index{CopyAutomaton@\texttt{CopyAutomaton}}
\label{CopyAutomaton}
}\hfill{\scriptsize (function)}}\\


 Returns a new automaton, which is a copy of automaton \mbox{\texttt{aut}}. }

 

\subsection{\textcolor{Chapter }{NullCompletionAutomaton}}
\logpage{[ 2, 5, 2 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{NullCompletionAutomaton( aut )\index{NullCompletionAutomaton@\texttt{NullCompletionAutomaton}}
\label{NullCompletionAutomaton}
}\hfill{\scriptsize (function)}}\\


 \texttt{aut} is a deterministic automaton. If it is complete returns \mbox{\texttt{aut}}, otherwise returns the completion (with a null state) of \mbox{\texttt{aut}}. Notice that the words recognized by \mbox{\texttt{aut}} and its completion are the same. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> aut:=Automaton("det",4,2,[[3,,3,4],[2,4,4,]],[1],[4]);;
  gap> IsDenseAutomaton(aut);
  false
  gap> y:=NullCompletionAutomaton(aut);;Display(y);
     |  1  2  3  4  5
  --------------------
   a |  3  5  3  4  5
   b |  2  4  4  5  5
  Initial state:   [ 1 ]
  Accepting state: [ 4 ]
\end{Verbatim}
 The state added is a \emph{sink state} i.e. it is a state $q$ which is not initial nor accepting and for all letter $a$ in the alphabet of the automaton, $q$ is the result of the action of $a$ in $q$. (Notice that reading a word, one does not go out of a sink state.) }

 

\subsection{\textcolor{Chapter }{ListSinkStatesAut}}
\logpage{[ 2, 5, 3 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{ListSinkStatesAut( aut )\index{ListSinkStatesAut@\texttt{ListSinkStatesAut}}
\label{ListSinkStatesAut}
}\hfill{\scriptsize (function)}}\\


 Computes the list of all sink states of the automaton \mbox{\texttt{aut}}. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> x:=Automaton("det",3,2,[ [ 2, 3, 3 ], [ 1, 2, 3 ] ],[ 1 ],[ 2, 3 ]);;
  gap> ListSinkStatesAut(x);
  [  ]
  gap> y:=Automaton("det",3,2,[ [ 2, 3, 3 ], [ 1, 2, 3 ] ],[ 1 ],[ 2 ]);;
  gap> ListSinkStatesAut(y);
  [ 3 ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{RemovedSinkStates}}
\logpage{[ 2, 5, 4 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{RemovedSinkStates( aut )\index{RemovedSinkStates@\texttt{RemovedSinkStates}}
\label{RemovedSinkStates}
}\hfill{\scriptsize (function)}}\\


 Removes all sink states of the automaton \mbox{\texttt{aut}}, changing its argument and returning nothing. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> y:=Automaton("det",3,2,[[ 2, 3, 3 ],[ 1, 2, 3 ]],[ 1 ],[ 2 ]);;Display(y);
     |  1  2  3
  --------------
   a |  2  3  3
   b |  1  2  3
  Initial state:   [ 1 ]
  Accepting state: [ 2 ]
  gap> RemovedSinkStates(y);Display(y);
     |  1  2
  -----------
   a |  2
   b |  1  2
  Initial state:   [ 1 ]
  Accepting state: [ 2 ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{ReversedAutomaton}}
\logpage{[ 2, 5, 5 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{ReversedAutomaton( aut )\index{ReversedAutomaton@\texttt{ReversedAutomaton}}
\label{ReversedAutomaton}
}\hfill{\scriptsize (function)}}\\


 Inverts the arrows of the automaton \mbox{\texttt{aut}}. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> y:=Automaton("det",3,2,[ [ 2, 3, 3 ], [ 1, 2, 3 ] ],[ 1 ],[ 2 ]);;
  gap> z:=ReversedAutomaton(y);;Display(z);
     |  1       2       3
  ------------------------------
   a |         [ 1 ]   [ 2, 3 ]
   b | [ 1 ]   [ 2 ]   [ 3 ]
  Initial state:   [ 2 ]
  Accepting state: [ 1 ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{PermutedAutomaton}}
\logpage{[ 2, 5, 6 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{PermutedAutomaton( aut, p )\index{PermutedAutomaton@\texttt{PermutedAutomaton}}
\label{PermutedAutomaton}
}\hfill{\scriptsize (function)}}\\


 Given an automaton \mbox{\texttt{aut}} and a list \mbox{\texttt{p}} representing a permutation of the states, outputs the equivalent permuted
automaton. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> y:=Automaton("det",4,2,[[2,3,4,2],[0,0,0,1]],[1],[3]);;Display(y);
     |  1  2  3  4
  -----------------
   a |  2  3  4  2
   b |           1
  Initial state:   [ 1 ]
  Accepting state: [ 3 ]
  gap> Display(PermutedAutomaton(y, [3,2,4,1]));
     |  1  2  3  4
  -----------------
   a |  2  4  2  1
   b |  3
  Initial state:   [ 3 ]
  Accepting state: [ 4 ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{ListPermutedAutomata}}
\logpage{[ 2, 5, 7 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{ListPermutedAutomata( aut )\index{ListPermutedAutomata@\texttt{ListPermutedAutomata}}
\label{ListPermutedAutomata}
}\hfill{\scriptsize (function)}}\\


 Given an automaton \mbox{\texttt{aut}}, returns a list of automata with permuted states 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> x:=Automaton("det",3,2,[ [ 0, 2, 3 ], [ 1, 2, 3 ] ],[ 1 ],[ 2, 3 ]);;
  gap> ListPermutedAutomata(x);
  [ < deterministic automaton on 2 letters with 3 states >, 
  < deterministic automaton on 2 letters with
      3 states >, < deterministic automaton on 2 letters with 3 states >,
    < deterministic automaton on 2 letters with 3 states >, 
  < deterministic automaton on 2 letters with
      3 states >, < deterministic automaton on 2 letters with 3 states > ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{NormalizedAutomaton}}
\logpage{[ 2, 5, 8 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{NormalizedAutomaton( A )\index{NormalizedAutomaton@\texttt{NormalizedAutomaton}}
\label{NormalizedAutomaton}
}\hfill{\scriptsize (function)}}\\


 Produces an equivalent automaton but in which the initial state is numbered 1
and the accepting states have the greatest numbers. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> x:=Automaton("det",3,2,[[ 1, 2, 0 ],[ 0, 1, 2 ]],[2],[1, 2]);;Display(x);
     |  1  2  3
  --------------
   a |  1  2
   b |     1  2
  Initial state:    [ 2 ]
  Accepting states: [ 1, 2 ]
  gap> Display(NormalizedAutomaton(x));
     |  1  2  3
  --------------
   a |  1     3
   b |  3  1
  Initial state:    [ 1 ]
  Accepting states: [ 3, 1 ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{UnionAutomata}}
\logpage{[ 2, 5, 9 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{UnionAutomata( A, B )\index{UnionAutomata@\texttt{UnionAutomata}}
\label{UnionAutomata}
}\hfill{\scriptsize (function)}}\\


 Produces the disjoint union of the deterministic or non deterministic automata \texttt{A} and \texttt{B}. The output is a non-deterministic automaton. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> x:=Automaton("det",3,2,[ [ 1, 2, 0 ], [ 0, 1, 2 ] ],[ 2 ],[ 1, 2 ]);;
  gap> y:=Automaton("det",3,2,[ [ 0, 1, 3 ], [ 0, 0, 0 ] ],[ 1 ],[ 1, 2, 3 ]);;
  gap> UnionAutomata(x,y);
  < non deterministic automaton on 2 letters with 6 states >
  gap> Display(last);
     |  1       2       3       4    5       6
  ------------------------------------------------
   a | [ 1 ]   [ 2 ]                [ 4 ]   [ 6 ]
   b |         [ 1 ]   [ 2 ]
  Initial states:   [ 2, 4 ]
  Accepting states: [ 1, 2, 4, 5, 6 ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{ProductAutomaton}}
\logpage{[ 2, 5, 10 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{ProductAutomaton( A1, A2 )\index{ProductAutomaton@\texttt{ProductAutomaton}}
\label{ProductAutomaton}
}\hfill{\scriptsize (function)}}\\


 The arguments must be deterministic automata. Returns the product of \mbox{\texttt{A1}} and \mbox{\texttt{A2}}. 

 Note: $(p,q)->(p-1)m+q$ is a bijection from $\{1,\ldots, n\}\times \{1,\ldots, m\}$ to $\{1,\ldots,mn\}$. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> x:=RandomAutomaton("det",3,2);;Display(x);
     |  1  2  3
  --------------
   a |  2  3
   b |     1
  Initial state:    [ 3 ]
  Accepting states: [ 1, 2, 3 ]
  gap> y:=RandomAutomaton("det",3,2);;Display(y);
     |  1  2  3
  --------------
   a |     1
   b |  1  3
  Initial state:    [ 3 ]
  Accepting states: [ 1, 3 ]
  gap> z:=ProductAutomaton(x, y);;Display(z);
     |  1  2  3  4  5  6  7  8  9
  --------------------------------
   a |     4        7
   b |           1  3
  Initial state:    [ 9 ]
  Accepting states: [ 1, 3, 4, 6, 7, 9 ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{ProductOfLanguages}}
\logpage{[ 2, 5, 11 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{ProductOfLanguages( A1, A2 )\index{ProductOfLanguages@\texttt{ProductOfLanguages}}
\label{ProductOfLanguages}
}\hfill{\scriptsize (function)}}\\


 Given two regular languages (as automata or rational expressions), returns an
automaton that recognizes the concatenation of the given languages, that is,
the set of words $uv$ such that $u$ belongs to the first language and $v$ belongs to the second language. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> a1:=ListOfWordsToAutomaton("ab",["aa","bb"]);
  < deterministic automaton on 2 letters with 5 states >
  gap> a2:=ListOfWordsToAutomaton("ab",["a","b"]);
  < deterministic automaton on 2 letters with 3 states >
  gap> ProductOfLanguages(a1,a2);
  < deterministic automaton on 2 letters with 5 states >
  gap> FAtoRatExp(last);
  (bbUaa)(aUb)
\end{Verbatim}
 }

 }

 
\section{\textcolor{Chapter }{Links with Semigroups}}\logpage{[ 2, 6, 0 ]}
{
 Each letter of the alphabet of an automaton induces a partial transformation
in its set of states. The semigroup generated by these transformations is
called the \emph{transition semigroup} of the automaton. 

\subsection{\textcolor{Chapter }{TransitionSemigroup}}
\logpage{[ 2, 6, 1 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{TransitionSemigroup( aut )\index{TransitionSemigroup@\texttt{TransitionSemigroup}}
\label{TransitionSemigroup}
}\hfill{\scriptsize (function)}}\\


 Returns the transition semigroup of the deterministic automaton \mbox{\texttt{aut}}. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> aut := Automaton("det",10,2,[[7,5,7,5,4,9,10,9,10,9],
  > [8,6,8,9,9,1,3,1,9,9]],[2],[6,7,8,9,10]);;
  gap> s := TransitionSemigroup(aut);;       
  gap> Size(s);                                                                  
  30
\end{Verbatim}
 The transition semigroup of the minimal automaton recognizing a language is
the {\it syntactic semigroup} of that language. }

 

\subsection{\textcolor{Chapter }{SyntacticSemigroupAut}}
\logpage{[ 2, 6, 2 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{SyntacticSemigroupAut( aut )\index{SyntacticSemigroupAut@\texttt{SyntacticSemigroupAut}}
\label{SyntacticSemigroupAut}
}\hfill{\scriptsize (function)}}\\


 Returns the syntactic semigroup of the deterministic automaton \mbox{\texttt{aut}} (i.e. the transition semigroup of the equivalent minimal automaton) when it is
non empty and returns \texttt{fail} otherwise. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> x:=Automaton("det",3,2,[ [ 1, 2, 0 ], [ 0, 1, 2 ] ],[ 2 ],[ 1, 2 ]);;
  gap> S:=SyntacticSemigroupAut(x);;
  gap> Size(S);
  3
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{SyntacticSemigroupLang}}
\logpage{[ 2, 6, 3 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{SyntacticSemigroupLang( rat )\index{SyntacticSemigroupLang@\texttt{SyntacticSemigroupLang}}
\label{SyntacticSemigroupLang}
}\hfill{\scriptsize (function)}}\\


 Returns the syntactic semigroup of the language given by the rational
expression \mbox{\texttt{rat}}. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> rat := RationalExpression("a*ba*ba*(@Ub)");;
  gap> S:=SyntacticSemigroupLang(rat);;
  gap> Size(S);
  7
\end{Verbatim}
 }

 }

 }

  
\chapter{\textcolor{Chapter }{Rational languages}}\logpage{[ 3, 0, 0 ]}
{
 Rational languages are conveniently represented through rational expressions.
These are finite expressions involving letters of the alphabet; \texttt{concatenation}, corresponding to the \emph{product}; the symbol \texttt{U}, corresponding to the \emph{union}; and the symbol \texttt{*}, corresponding to the Kleene's star. \index{rational expressions} 
\section{\textcolor{Chapter }{Rational Expressions}}\logpage{[ 3, 1, 0 ]}
{
 The expressions \texttt{@} and \texttt{"empty\_set"} are used to represent the empty word and the empty set respectively. 

\subsection{\textcolor{Chapter }{RationalExpression}}
\logpage{[ 3, 1, 1 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{RationalExpression( expr[, alph] )\index{RationalExpression@\texttt{RationalExpression}}
\label{RationalExpression}
}\hfill{\scriptsize (function)}}\\


 A rational expression can be created using the function \texttt{RationalExpression}. \mbox{\texttt{expr}} is a string representing the desired expression literally and \mbox{\texttt{alph}} (may or may not be present) is the alphabet of the expression. Of course \mbox{\texttt{alph}} must not contain the symbols '@', '(', ')', '*' nor 'U'. When \mbox{\texttt{alph}} is not present, the alphabet of the rational expression is the set of symbols
(other than '"', etc...) occurring in the expression. (The alphabet is then
ordered with the alphabetical order.) 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> RationalExpression("abUc");
  abUc
  gap> RationalExpression("ab*Uc");
  ab*Uc
  gap> RationalExpression("001U1*");
  001U1*
  gap> RationalExpression("001U1*","012");
  001U1*
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{RatExpOnnLetters}}
\logpage{[ 3, 1, 2 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{RatExpOnnLetters( n, operation, list )\index{RatExpOnnLetters@\texttt{RatExpOnnLetters}}
\label{RatExpOnnLetters}
}\hfill{\scriptsize (function)}}\\


 This is another way to construct a rational expression over an alphabet. The
user may specify the alphabet or just give the number $n$ of letters (in this case the alphabet $\{a,b,c,\ldots\}$ is considered). \mbox{\texttt{operation}} is the name of an operation, the possibilities being: \texttt{product}, \texttt{union} or \texttt{star}. \mbox{\texttt{list}} is a list of rational expressions, a rational expression in the case of
``star'', or a list consisting of an integer when the rational expression is a
single letter. The empty list \texttt{[ ]} and \texttt{empty\_set} are other possibilities for \texttt{list}. An example follows 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> RatExpOnnLetters(2,"star",RatExpOnnLetters(2,"product",
  > [RatExpOnnLetters(2,[],[1]),RatExpOnnLetters(2,"union",
  > [RatExpOnnLetters(2,[],[1]),RatExpOnnLetters(2,[],[2])])]));      
  (a(aUb))*
\end{Verbatim}
 The empty word and the empty set are the rational expressions: 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> RatExpOnnLetters(2,[],[]);         
  @
  gap> RatExpOnnLetters(2,[],"empty_set");
  empty_set
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{RandomRatExp}}
\logpage{[ 3, 1, 3 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{RandomRatExp( arg )\index{RandomRatExp@\texttt{RandomRatExp}}
\label{RandomRatExp}
}\hfill{\scriptsize (function)}}\\


 Given the number of symbols of the alphabet and (possibly) a factor $m$ which is intended to increase the randomality of the expression, returns a
pseudo random rational expression over that alphabet. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> RandomRatExp(2);
  b*(@Ua)
  gap> RandomRatExp("01");
  empty_set
  gap> RandomRatExp("01");
  (0U1)*
  gap> RandomRatExp("01",7);
  0*1(@U0U1)
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{SizeRatExp}}
\logpage{[ 3, 1, 4 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{SizeRatExp( r )\index{SizeRatExp@\texttt{SizeRatExp}}
\label{SizeRatExp}
}\hfill{\scriptsize (function)}}\\


 Returns the size, i.e. the number of symbols of the alphabet, of the rational
expression \mbox{\texttt{r}}. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> a:=RationalExpression("0*1(@U0U1)");
  0*1(@U0U1)
  gap> SizeRatExp(a);
  4
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{IsRationalExpression}}
\logpage{[ 3, 1, 5 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{IsRationalExpression( r )\index{IsRationalExpression@\texttt{IsRationalExpression}}
\label{IsRationalExpression}
}\hfill{\scriptsize (function)}}\\


 Tests whether an object is a rational expression. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> IsRatExpOnnLettersObj(r3) and IsRationalExpressionRep(r3);
  true
  gap> IsRationalExpression(r1);
  true
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{AlphabetOfRatExp}}
\logpage{[ 3, 1, 6 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{AlphabetOfRatExp( R )\index{AlphabetOfRatExp@\texttt{AlphabetOfRatExp}}
\label{AlphabetOfRatExp}
}\hfill{\scriptsize (function)}}\\


 Returns the alphabet of the rational expression \texttt{R}. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> r:=RandomRatExp(2);
  a*(ba*U@)
  gap> AlphabetOfRatExp(r);
  2
  gap> r:=RandomRatExp("01");
  1*(01*U@)
  gap> AlphabetOfRatExp(r);
  "01"
  gap> a:=RandomTransformation(3);;
  gap> b:=RandomTransformation(3);;
  gap> r:=RandomRatExp([a,b]);
  (Transformation( [ 1, 1, 3 ] )UTransformation( [ 1, 1, 2 ] ))*
  gap> AlphabetOfRatExp(r);
  [ Transformation( [ 1, 1, 3 ] ), Transformation( [ 1, 1, 2 ] ) ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{AlphabetOfRatExpAsList}}
\logpage{[ 3, 1, 7 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{AlphabetOfRatExpAsList( R )\index{AlphabetOfRatExpAsList@\texttt{AlphabetOfRatExpAsList}}
\label{AlphabetOfRatExpAsList}
}\hfill{\scriptsize (function)}}\\


 Returns the alphabet of the rational expression \texttt{R} always as a list. If the alphabet of the rational expression is an integer
less than 27 it returns the list \texttt{"abcd...."}, otherwise returns \texttt{[ "a1", "a2", "a3", "a4", ... ]}. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> r:=RandomRatExp(2);
  (aUb)((aUb)(bU@)U@)U@
  gap> AlphabetOfRatExpAsList(r);
  "ab"
  gap> r:=RandomRatExp("01");
  1*(0U@)
  gap> AlphabetOfRatExpAsList(r);
  "01"
  gap> r:=RandomRatExp(30);;
  gap> AlphabetOfRatExpAsList(r);
  [ "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10", "a11", 
  "a12", "a13", "a14", "a15", "a16", "a17", "a18", "a19", "a20", "a21", 
  "a22", "a23", "a24", "a25", "a26", "a27", "a28", "a29", "a30" ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{CopyRatExp}}
\logpage{[ 3, 1, 8 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{CopyRatExp( R )\index{CopyRatExp@\texttt{CopyRatExp}}
\label{CopyRatExp}
}\hfill{\scriptsize (function)}}\\


 Returns a new rational expression, which is a copy of \texttt{R}. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> r:=RandomRatExp(2);
  a*(bU@)
  gap> CopyRatExp(r);
  a*(bU@)
\end{Verbatim}
 }

 }

 
\section{\textcolor{Chapter }{Comparison of rational expressions}}\logpage{[ 3, 2, 0 ]}
{
 The way two rational expressions \texttt{r1} and \texttt{r2} are compared through the  $<$   operator is the following: the empty set is lesser than everything else; if r1
and r2 are letters, then the lesser is taken from the order in the alphabet;
if r1 is a letter an r2 a product, union or star, then r1 is lesser than r2; a
star expression is considered to be lesser than a product or union expression
and a product lesser than a union; to compare two star expressions we compare
the expressions under the stars; to compare two product or union expressions
we compare the subexpressions of each expression from left to right; }

 
\section{\textcolor{Chapter }{Operations with rational languages}}\logpage{[ 3, 3, 0 ]}
{
 Only operations with rational languages over the same alphabet are allowed. 

 We may compute expressions for the \texttt{product}, \texttt{union} and \texttt{star} (i.e., submonoid generated by) of rational sets. In some cases, simpler
expressions representing the same set are returned. Note that that two
simplifications are always made, namely,  $r\cup"empty_set" = r$   and  $r\epsilon = r$  . Of course, these operations may be used to construct more complex
expressions. For rational expressions we have the functions \texttt{UnionRatExp}, \texttt{ProductRatExp}, \texttt{StarRatExp}, that return respectively rational expressions for the \emph{union} and \emph{product} of the languages given by the rational expressions \texttt{r} and \texttt{s} and the \texttt{star} of the language given by the rational expression \texttt{r}. 

\subsection{\textcolor{Chapter }{UnionRatExp}}
\logpage{[ 3, 3, 1 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{UnionRatExp( r, s )\index{UnionRatExp@\texttt{UnionRatExp}}
\label{UnionRatExp}
}\hfill{\scriptsize (function)}}\\
}

 

\subsection{\textcolor{Chapter }{ProductRatExp}}
\logpage{[ 3, 3, 2 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{ProductRatExp( r, s )\index{ProductRatExp@\texttt{ProductRatExp}}
\label{ProductRatExp}
}\hfill{\scriptsize (function)}}\\
}

 

\subsection{\textcolor{Chapter }{ StarRatExp}}
\logpage{[ 3, 3, 3 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{ StarRatExp( r )\index{ StarRatExp@\texttt{ StarRatExp}}
\label{ StarRatExp}
}\hfill{\scriptsize (function)}}\\


 The expression \texttt{(a(aUb))*} may be produced in the following way 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> r1 := RatExpOnnLetters(2,[],[1]); 
  a
  gap> r2 := RatExpOnnLetters(2,[],[2]);
  b
  gap> r3 := UnionRatExp(r1,r2);
  aUb
  gap> r4 := ProductRatExp(r1,r3);
  a(aUb)
  gap> r5 := StarRatExp(r4);
  (a(aUb))*
\end{Verbatim}
 }

 }

 }

  
\chapter{\textcolor{Chapter }{Automata \emph{versus} rational expressions}}\logpage{[ 4, 0, 0 ]}
{
 A remarkable theorem due to Kleene shows that a language is recognized by a
finite automaton precisely when it may be given by means of a rational
expression, i.e. is a rational language. 

 An automaton and a rational expression are said to be \emph{equivalent} when both represent the same language. In this chapter we describe functions
to go from automata to equivalent rational expressions and \emph{vice-versa}. 
\section{\textcolor{Chapter }{From automata to rational expressions}}\logpage{[ 4, 1, 0 ]}
{
 

\subsection{\textcolor{Chapter }{AutomatonToRatExp }}
\logpage{[ 4, 1, 1 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{AutomatonToRatExp ( A )\index{AutomatonToRatExp @\texttt{AutomatonToRatExp }}
\label{AutomatonToRatExp }
}\hfill{\scriptsize (function)}}\\
\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{AutToRatExp( A )\index{AutToRatExp@\texttt{AutToRatExp}}
\label{AutToRatExp}
}\hfill{\scriptsize (function)}}\\
\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{FAtoRatExp( A )\index{FAtoRatExp@\texttt{FAtoRatExp}}
\label{FAtoRatExp}
}\hfill{\scriptsize (function)}}\\


 From a finite automaton, \texttt{FAtoRatExp}, \texttt{AutToRatExp} and \texttt{AutomatonToRatExp}, which are synonyms, compute one equivalent rational expression, using the
state elimination algorithm. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> x:=Automaton("det",4,2,[[ 0, 1, 2, 3 ],[ 0, 1, 2, 3 ]],[ 3 ],[ 1, 3, 4 ]);;
  gap> FAtoRatExp(x);
  (aUb)(aUb)U@
\end{Verbatim}
 }

 }

 
\section{\textcolor{Chapter }{From rational expression to automata}}\logpage{[ 4, 2, 0 ]}
{
 

\subsection{\textcolor{Chapter }{RatExpToNDAut}}
\logpage{[ 4, 2, 1 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{RatExpToNDAut( R )\index{RatExpToNDAut@\texttt{RatExpToNDAut}}
\label{RatExpToNDAut}
}\hfill{\scriptsize (function)}}\\


 Given a rational expression \mbox{\texttt{R}}, computes the equivalent NFA 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> r:=RationalExpression("aUab");
  aUab
  gap> Display(RatExpToNDAut(r));
     |  1    2       3    4
  --------------------------------
   a |                   [ 1, 2 ]
   b |      [ 3 ]
  Initial state:    [ 4 ]
  Accepting states: [ 1, 3 ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{RatExpToAutomaton}}
\logpage{[ 4, 2, 2 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{RatExpToAutomaton( R )\index{RatExpToAutomaton@\texttt{RatExpToAutomaton}}
\label{RatExpToAutomaton}
}\hfill{\scriptsize (function)}}\\
\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{RatExpToAut( R )\index{RatExpToAut@\texttt{RatExpToAut}}
\label{RatExpToAut}
}\hfill{\scriptsize (function)}}\\


 Given a rational expression \mbox{\texttt{R}}, these functions, which are synonyms, use \texttt{RatExpToNDAut} (\ref{RatExpToNDAut})) to compute the equivalent NFA and then returns the equivalent minimal DFA 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> r:=RationalExpression("@U(aUb)(aUb)");
  @U(aUb)(aUb)
  gap> Display(RatExpToAut(r));
     |  1  2  3  4
  -----------------
   a |  3  1  3  2
   b |  3  1  3  2
  Initial state:    [ 4 ]
  Accepting states: [ 1, 4 ]
\end{Verbatim}
 }

 }

 
\section{\textcolor{Chapter }{ Some tests on automata }}\logpage{[ 4, 3, 0 ]}
{
  This section describes functions that perform tests on automata, rational
expressions and their accepted languages. 

\subsection{\textcolor{Chapter }{IsEmptyLang}}
\logpage{[ 4, 3, 1 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{IsEmptyLang( R )\index{IsEmptyLang@\texttt{IsEmptyLang}}
\label{IsEmptyLang}
}\hfill{\scriptsize (function)}}\\


 This function tests if the language given through a rational expression or an
automaton \mbox{\texttt{ R }} is the empty language. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> r:=RandomRatExp(2);
  empty_set
  gap> IsEmptyLang(r);
  true
  gap> r:=RandomRatExp(2);
  aUb
  gap> IsEmptyLang(r);
  false
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{IsFullLang}}
\logpage{[ 4, 3, 2 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{IsFullLang( R )\index{IsFullLang@\texttt{IsFullLang}}
\label{IsFullLang}
}\hfill{\scriptsize (function)}}\\


 This function tests if the language given through a rational expression or an
automaton \mbox{\texttt{ R }} represents the Kleene closure of the alphabet of \mbox{\texttt{ R }} . 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> r:=RationalExpression("aUb");
  aUb
  gap> IsFullLang(r);
  false
  gap> r:=RationalExpression("(aUb)*");
  (aUb)*
  gap> IsFullLang(r);
  true
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{AreEqualLang}}
\logpage{[ 4, 3, 3 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{AreEqualLang( A1, A2 )\index{AreEqualLang@\texttt{AreEqualLang}}
\label{AreEqualLang}
}\hfill{\scriptsize (function)}}\\
\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{AreEquivAut( A1, A2 )\index{AreEquivAut@\texttt{AreEquivAut}}
\label{AreEquivAut}
}\hfill{\scriptsize (function)}}\\


 These functions, which are synonyms, test if the automata or rational
expressions \mbox{\texttt{A1}} and \mbox{\texttt{A2}} are equivalent, i.e. represent the same language. This is performed by
checking that the corresponding minimal automata are isomorphic. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> y:=RandomAutomaton("det",4,2);;
  gap> x:=RandomAutomaton("det",4,2);;
  gap> AreEquivAut(x, y);
  false
  gap> a:=RationalExpression("(aUb)*ab*");
  (aUb)*ab*
  gap> b:=RationalExpression("(aUb)*");
  (aUb)*
  gap> AreEqualLang(a, b);
  false
  gap> a:=RationalExpression("(bUa)*");
  (bUa)*
  gap> AreEqualLang(a, b);
  true
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{IsContainedLang}}
\logpage{[ 4, 3, 4 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{IsContainedLang( R1, R2 )\index{IsContainedLang@\texttt{IsContainedLang}}
\label{IsContainedLang}
}\hfill{\scriptsize (function)}}\\


 Tests if the language represented (through an automaton or a rational
expression) by \mbox{\texttt{ R1 }} is contained in the language represented (through an automaton or a rational
expression) by \mbox{\texttt{ R2 }} . 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> r:=RationalExpression("aUab");
  aUab
  gap> s:=RationalExpression("a","ab");
  a
  gap> IsContainedLang(s,r);
  true
  gap> IsContainedLang(r,s);
  false
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{AreDisjointLang}}
\logpage{[ 4, 3, 5 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{AreDisjointLang( R1, R2 )\index{AreDisjointLang@\texttt{AreDisjointLang}}
\label{AreDisjointLang}
}\hfill{\scriptsize (function)}}\\


 Tests if the languages represented (through automata or a rational
expressions) by \mbox{\texttt{ R1 }} and \mbox{\texttt{ R2 }} are disjoint. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> r:=RationalExpression("aUab");;
  gap> s:=RationalExpression("a","ab");;
  gap> AreDisjointLang(r,s);
  false
\end{Verbatim}
 }

 }

 }

  
\chapter{\textcolor{Chapter }{Some functions involving automata}}\logpage{[ 5, 0, 0 ]}
{
 This chapter describes some functions involving automata. It starts with
functions to obtain equivalent automata of other type. Then the minimalization
is considered. 
\section{\textcolor{Chapter }{From one type to another}}\logpage{[ 5, 1, 0 ]}
{
 Recall that two automata are said to be equivalent when they recognize the
same language. Next we have functions which have as input automata of one type
and as output equivalent automata of another type. 

\subsection{\textcolor{Chapter }{EpsilonToNFA}}
\logpage{[ 5, 1, 1 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{EpsilonToNFA( A )\index{EpsilonToNFA@\texttt{EpsilonToNFA}}
\label{EpsilonToNFA}
}\hfill{\scriptsize (function)}}\\


 \mbox{\texttt{A}} is an automaton with $\epsilon$-transitions. Returns a NFA recognizing the same language. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> x:=RandomAutomaton("epsilon",3,2);;Display(x);
     |  1          2          3
  ------------------------------------
   a | [ 2 ]      [ 3 ]      [ 2 ]
   b | [ 1, 2 ]   [ 1, 2 ]   [ 1, 3 ]
   @ | [ 1, 2 ]   [ 1, 2 ]   [ 1, 2 ]
  Initial states:   [ 2, 3 ]
  Accepting states: [ 1, 2, 3 ]
  gap> Display(EpsilonToNFA(x));
     |  1          2             3
  ------------------------------------------
   a | [ 1, 2 ]   [ 1, 2, 3 ]   [ 1, 2 ]
   b | [ 1, 2 ]   [ 1, 2 ]      [ 1, 2, 3 ]
  Initial states:   [ 1, 2, 3 ]
  Accepting states: [ 1, 2, 3 ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{EpsilonToNFASet}}
\logpage{[ 5, 1, 2 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{EpsilonToNFASet( A )\index{EpsilonToNFASet@\texttt{EpsilonToNFASet}}
\label{EpsilonToNFASet}
}\hfill{\scriptsize (function)}}\\


 \mbox{\texttt{A}} is an automaton with $\epsilon$-transitions. Returns a NFA recognizing the same language. This function
differs from \texttt{EpsilonToNFA} (\ref{EpsilonToNFA}) in that it is faster for smaller automata, or automata with few epsilon
transitions, but slower in the really hard cases. }

 

\subsection{\textcolor{Chapter }{EpsilonCompactedAut}}
\logpage{[ 5, 1, 3 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{EpsilonCompactedAut( A )\index{EpsilonCompactedAut@\texttt{EpsilonCompactedAut}}
\label{EpsilonCompactedAut}
}\hfill{\scriptsize (function)}}\\


 \mbox{\texttt{A}} is an automaton with $\epsilon$-transitions. Returns an $\epsilon$NFA with each strongly-connected component of the epsilon-transitions digraph
of \mbox{\texttt{A}} identified with a single state and recognizing the same language. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> x:=RandomAutomaton("epsilon",3,2);;Display(x);
     |  1          2          3
  ------------------------------------
   a | [ 1, 2 ]   [ 1, 3 ]   [ 1, 2 ]
   b | [ 1, 2 ]   [ 1, 2 ]   [ 2, 3 ]
   @ |            [ 3 ]      [ 2 ]
  Initial state:    [ 3 ]
  Accepting states: [ 1, 3 ]
  gap> Display(EpsilonCompactedAut(x));
     |  1          2
  -------------------------
   a | [ 1, 2 ]   [ 1, 2 ]
   b | [ 1, 2 ]   [ 1, 2 ]
   @ |
  Initial state:    [ 2 ]
  Accepting states: [ 1, 2 ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{ReducedNFA}}
\logpage{[ 5, 1, 4 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{ReducedNFA( A )\index{ReducedNFA@\texttt{ReducedNFA}}
\label{ReducedNFA}
}\hfill{\scriptsize (function)}}\\


 \mbox{\texttt{A}} is a non deterministic automaton (without $\epsilon$-transitions). Returns an NFA accepting the same language as its input but
with possibly fewer states (it quotients out by the smallest right-invariant
partition of the states). A paper describing the algorithm is in preparation. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> x:=RandomAutomaton("nondet",5,2);;Display(x);
     |  1             2                3             4             5
  ----------------------------------------------------------------------
   a | [ 1, 5 ]      [ 1, 2, 4, 5 ]   [ 1, 3, 5 ]   [ 3, 4, 5 ]   [ 4 ]
   b | [ 2, 3, 4 ]   [ 3 ]            [ 2, 3, 4 ]   [ 2, 4, 5 ]   [ 3 ]
  Initial state:    [ 4 ]
  Accepting states: [ 1, 3, 4, 5 ]
  gap> Display(ReducedNFA(x));
     |  1             2                3       4
  --------------------------------------------------------
   a | [ 1, 3 ]      [ 1, 2, 3, 4 ]   [ 4 ]   [ 1, 3, 4 ]
   b | [ 1, 2, 4 ]   [ 1 ]            [ 1 ]   [ 2, 3, 4 ]
  Initial state:    [ 4 ]
  Accepting states: [ 1, 3, 4 ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{NFAtoDFA}}
\logpage{[ 5, 1, 5 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{NFAtoDFA( A )\index{NFAtoDFA@\texttt{NFAtoDFA}}
\label{NFAtoDFA}
}\hfill{\scriptsize (function)}}\\


 Given an NFA, these synonym functions, compute the equivalent DFA, using the
powerset construction, according to the algorithm presented in the report of
the AMoRE \cite{AMORE:95} program. The returned automaton is dense deterministic 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> x:=RandomAutomaton("nondet",3,2);;Display(x);
     |  1       2    3
  ---------------------------
   a | [ 2 ]        [ 1, 3 ]
   b |              [ 2, 3 ]
  Initial states:   [ 1, 3 ]
  Accepting states: [ 1, 2 ]
  gap> Display(NFAtoDFA(x));
     |  1  2  3
  --------------
   a |  2  2  1
   b |  3  3  3
  Initial state:    [ 1 ]
  Accepting states: [ 1, 2, 3 ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{FuseSymbolsAut}}
\logpage{[ 5, 1, 6 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{FuseSymbolsAut( A, s1, s2 )\index{FuseSymbolsAut@\texttt{FuseSymbolsAut}}
\label{FuseSymbolsAut}
}\hfill{\scriptsize (function)}}\\


 Given an automaton \mbox{\texttt{A}} and integers \mbox{\texttt{s1}} and \mbox{\texttt{s2}} which, returns an NFA obtained by replacing all transitions through \mbox{\texttt{s2}} by transitions through \mbox{\texttt{s1}}. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> x:=RandomAutomaton("det",3,2);;Display(x);
     |  1  2  3
  --------------
   a |  2  3
   b |     1
  Initial state:    [ 3 ]
  Accepting states: [ 1, 2, 3 ]
  gap> Display(FuseSymbolsAut(x,1,2));
     |  1       2          3
  ---------------------------
   a | [ 2 ]   [ 1, 3 ]
  Initial state:    [ 3 ]
  Accepting states: [ 1, 2, 3 ]
\end{Verbatim}
 }

 }

 
\section{\textcolor{Chapter }{Minimalization of an automaton}}\logpage{[ 5, 2, 0 ]}
{
 The algorithm used to minimalize a dense deterministic automaton (i.e., to
compute a dense minimal automaton recognizing the same language) is based on
an algorithm due to Hopcroft (see \cite{AHU:74}). It is well known (see \cite{HU:69}) that it suffices to reduce the automaton given and remove the inaccessible
states. Again, the documentation for the computer program AMoRE \cite{AMORE:95} has been very useful. 

\subsection{\textcolor{Chapter }{UsefulAutomaton}}
\logpage{[ 5, 2, 1 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{UsefulAutomaton( A )\index{UsefulAutomaton@\texttt{UsefulAutomaton}}
\label{UsefulAutomaton}
}\hfill{\scriptsize (function)}}\\


 Given an automaton \mbox{\texttt{A}} (deterministic or not), outputs a dense DFA \mbox{\texttt{B}} whose states are all reachable and such that \mbox{\texttt{A}} and \mbox{\texttt{B}} are equivalent. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> x:=RandomAutomaton("det",4,2);;Display(x);
     |  1  2  3  4
  -----------------
   a |     3  4
   b |  1  4
  Initial state:    [ 3 ]
  Accepting states: [ 2, 3, 4 ]
  gap> Display(UsefulAutomaton(x));
     |  1  2  3
  --------------
   a |  2  3  3
   b |  3  3  3
  Initial state:    [ 1 ]
  Accepting states: [ 1, 2 ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{MinimalizedAut}}
\logpage{[ 5, 2, 2 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{MinimalizedAut( A )\index{MinimalizedAut@\texttt{MinimalizedAut}}
\label{MinimalizedAut}
}\hfill{\scriptsize (function)}}\\


 Returns the minimal automaton equivalent to \mbox{\texttt{A}}. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> x:=RandomAutomaton("det",4,2);;Display(x);
     |  1  2  3  4
  -----------------
   a |     3  4
   b |  1  2  3
  Initial state:    [ 4 ]
  Accepting states: [ 2, 3, 4 ]
  gap> Display(MinimalizedAut(x));
     |  1  2
  -----------
   a |  2  2
   b |  2  2
  Initial state:   [ 1 ]
  Accepting state: [ 1 ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{ MinimalAutomaton}}
\logpage{[ 5, 2, 3 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{ MinimalAutomaton( A )\index{ MinimalAutomaton@\texttt{ MinimalAutomaton}}
\label{ MinimalAutomaton}
}\hfill{\scriptsize (attribute)}}\\


 Returns the minimal automaton equivalent to \mbox{\texttt{A}}, but stores it so that future computations of this automaton just return the
stored automaton. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> x:=RandomAutomaton("det",4,2);;Display(x);
     |  1  2  3  4
  -----------------
   a |     2  4
   b |     3  4
  Initial state:    [ 4 ]
  Accepting states: [ 1, 2, 3 ]
  gap> Display(MinimalAutomaton(x));
     |  1
  --------
   a |  1
   b |  1
  Initial state:   [ 1 ]
  Accepting state:
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{AccessibleStates}}
\logpage{[ 5, 2, 4 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{AccessibleStates( aut[, p] )\index{AccessibleStates@\texttt{AccessibleStates}}
\label{AccessibleStates}
}\hfill{\scriptsize (function)}}\\


 Computes the list of states of the automaton \mbox{\texttt{aut}} which are accessible from state \mbox{\texttt{p}}. When \mbox{\texttt{p}} is not given, returns the states which are accessible from any initial state. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> x:=RandomAutomaton("det",4,2);;Display(x);
     |  1  2  3  4
  -----------------
   a |     1  2  4
   b |     2  4
  Initial state:    [ 2 ]
  Accepting states: [ 1, 2, 3 ]
  gap> AccessibleStates(x,3);
  [ 1, 2, 3, 4 ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{AccessibleAutomaton}}
\logpage{[ 5, 2, 5 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{AccessibleAutomaton( A )\index{AccessibleAutomaton@\texttt{AccessibleAutomaton}}
\label{AccessibleAutomaton}
}\hfill{\scriptsize (function)}}\\


 If \mbox{\texttt{A}} is a deterministic automaton, not necessarily dense, an equivalent dense
deterministic accessible automaton is returned. (The function \texttt{UsefulAutomaton} is called.) 

 If \mbox{\texttt{A}} is not deterministic with a single initial state, an equivalent accessible
automaton is returned. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> x:=RandomAutomaton("det",4,2);;Display(x);
     |  1  2  3  4
  -----------------
   a |  1  3
   b |  1  3  4
  Initial state:    [ 2 ]
  Accepting states: [ 3, 4 ]
  gap> Display(AccessibleAutomaton(x));
     |  1  2  3  4
  -----------------
   a |  2  4  4  4
   b |  2  3  4  4
  Initial state:    [ 1 ]
  Accepting states: [ 2, 3 ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{IntersectionLanguage}}
\logpage{[ 5, 2, 6 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{IntersectionLanguage( A1, A2 )\index{IntersectionLanguage@\texttt{IntersectionLanguage}}
\label{IntersectionLanguage}
}\hfill{\scriptsize (function)}}\\
\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{IntersectionAutomaton( A1, A2 )\index{IntersectionAutomaton@\texttt{IntersectionAutomaton}}
\label{IntersectionAutomaton}
}\hfill{\scriptsize (function)}}\\


 Computes an automaton that recognizes the intersection of the languages given
(through automata or rational expressions by) \mbox{\texttt{A1}} and \mbox{\texttt{A2}}. When the arguments are deterministic automata, is the same as
ProductAutomaton, but works for all kinds of automata. Note that the language
of the product of two automata is precisely the intersection of the languages
of the automata. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> x:=RandomAutomaton("det",3,2);;Display(x);
     |  1  2  3
  --------------
   a |  2  3
   b |     1
  Initial state:    [ 3 ]
  Accepting states: [ 1, 2, 3 ]
  gap> y:=RandomAutomaton("det",3,2);;Display(y);
     |  1  2  3
  --------------
   a |     1
   b |  1  3
  Initial state:    [ 3 ]
  Accepting states: [ 1, 3 ]
  gap> Display(IntersectionLanguage(x,y));
     |  1  2
  -----------
   a |  2  2
   b |  2  2
  Initial state:   [ 1 ]
  Accepting state: [ 1 ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{AutomatonAllPairsPaths}}
\logpage{[ 5, 2, 7 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{AutomatonAllPairsPaths( A )\index{AutomatonAllPairsPaths@\texttt{AutomatonAllPairsPaths}}
\label{AutomatonAllPairsPaths}
}\hfill{\scriptsize (function)}}\\


 Given an automaton \mbox{\texttt{A}}, with \texttt{n} states, outputs a \texttt{n} x \texttt{n} matrix P, such that P[i][j] is the list of simple paths from state i to state
j in \mbox{\texttt{A}}. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> a:=RandomAutomaton("det",3,2);
  < deterministic automaton on 2 letters with 3 states >
  gap> AutomatonAllPairsPaths(a);
  [ [ [ [ 1, 1 ] ], [  ], [  ] ], [ [ [ 2, 1 ] ], [ [ 2, 2 ] ], [  ] ],
    [ [ [ 3, 2, 1 ] ], [ [ 3, 2 ] ], [ [ 3, 3 ] ] ] ]
  gap> Display(a);
     |  1  2  3
  --------------
   a |     1  2
   b |  1  2  3
  Initial state:    [ 3 ]
  Accepting states: [ 1, 2 ]
\end{Verbatim}
 }

 }

 }

  
\chapter{\textcolor{Chapter }{Finite regular languages}}\logpage{[ 6, 0, 0 ]}
{
 This chapter describes some functions to deal with finite regular languages. 
\section{\textcolor{Chapter }{Dealing with finite regular languages}}\logpage{[ 6, 1, 0 ]}
{
 

\subsection{\textcolor{Chapter }{IsFiniteRegularLanguage}}
\logpage{[ 6, 1, 1 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{IsFiniteRegularLanguage( L )\index{IsFiniteRegularLanguage@\texttt{IsFiniteRegularLanguage}}
\label{IsFiniteRegularLanguage}
}\hfill{\scriptsize (function)}}\\


 \mbox{\texttt{L}} is an automaton or a rational expression. This function tests whether its
argument represents a finite language or not. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> RandomRatExp(2);
  b*(aU@)
  gap> IsFiniteRegularLanguage(last);
  false
  gap> RandomRatExp(2);
  aUbU@
  gap> IsFiniteRegularLanguage(last);
  true
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{FiniteRegularLanguageToListOfWords}}
\logpage{[ 6, 1, 2 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{FiniteRegularLanguageToListOfWords( L )\index{FiniteRegularLanguageToListOfWords@\texttt{FiniteRegularLanguageToListOfWords}}
\label{FiniteRegularLanguageToListOfWords}
}\hfill{\scriptsize (function)}}\\


 \mbox{\texttt{L}} is an automaton or a rational expression. This function outputs the recognized
language as a list of words. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> r:=RationalExpression("aaUb(aUb)");
  aaUb(aUb)
  gap> FiniteRegularLanguageToListOfWords(r);
  [ "aa", "ba", "bb" ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{ListOfWordsToAutomaton}}
\logpage{[ 6, 1, 3 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{ListOfWordsToAutomaton( alph, L )\index{ListOfWordsToAutomaton@\texttt{ListOfWordsToAutomaton}}
\label{ListOfWordsToAutomaton}
}\hfill{\scriptsize (function)}}\\


 Given an alphabet \mbox{\texttt{alph}} (a list) and a list of words \mbox{\texttt{L}} (a list of lists), outputs an automaton that recognizes the given list of
words. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> ListOfWordsToAutomaton("ab",["aaa","bba",""]);
  < deterministic automaton on 2 letters with 6 states >
  gap> FAtoRatExp(last);
  (bbUaa)aU@
\end{Verbatim}
 }

 }

 }

 

\appendix


\chapter{\textcolor{Chapter }{Directed graphs}}\logpage{[ "A", 0, 0 ]}
{
 Automata are frequently described through directed labeled graphs. This
appendix on directed graphs (digraphs) is devoted to some functions designed
with the purpose of being used as auxiliary functions to deal with automata,
but may have independent interest. 
\section{\textcolor{Chapter }{Directed graphs}}\logpage{[ "A", 1, 0 ]}
{
 A directed graph with $n$ vertices is represented by an adjacency list. For example, the list \texttt{G = [[2,4],[3],[1,4],[]]} represents a directed graph with \texttt{4 (= Length(G))} vertices; the sublist in position \texttt{i} is the list of endpoints of the edges beginning in vertex $i$.  \begin{figure}[htbp] \begin{center} \leavevmode \includegraphics[bb=0 0 132
299]{graph} \end{center} \label{fig:graph} \end{figure}   

 

\subsection{\textcolor{Chapter }{RandomDiGraph}}
\logpage{[ "A", 1, 1 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{RandomDiGraph( n )\index{RandomDiGraph@\texttt{RandomDiGraph}}
\label{RandomDiGraph}
}\hfill{\scriptsize (function)}}\\


 Produces a pseudo random digraph with $n$ vertices 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> RandomDiGraph(4);
  [ [  ], [ 1, 2, 4 ], [  ], [  ] ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{VertexInDegree}}
\logpage{[ "A", 1, 2 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{VertexInDegree( DG, v )\index{VertexInDegree@\texttt{VertexInDegree}}
\label{VertexInDegree}
}\hfill{\scriptsize (function)}}\\


 Computes the in degree of the vertex \mbox{\texttt{v}} of the directed graph \mbox{\texttt{DG}} 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> G:=RandomDiGraph(4);
  [ [ 1 ], [ 1, 2, 4 ], [  ], [ 1, 2, 3 ] ]
  gap> VertexInDegree(G,2);
  2
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{VertexOutDegree}}
\logpage{[ "A", 1, 3 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{VertexOutDegree( DG, v )\index{VertexOutDegree@\texttt{VertexOutDegree}}
\label{VertexOutDegree}
}\hfill{\scriptsize (function)}}\\


 Computes the out degree of the vertex \mbox{\texttt{v}} of the directed graph \mbox{\texttt{DG}} 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> G:=RandomDiGraph(4);
  [ [ 1 ], [ 1, 2, 4 ], [  ], [ 1, 2, 3 ] ]
  gap> VertexOutDegree(G,2);
  3
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{AutoVertexDegree}}
\logpage{[ "A", 1, 4 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{AutoVertexDegree( DG, v )\index{AutoVertexDegree@\texttt{AutoVertexDegree}}
\label{AutoVertexDegree}
}\hfill{\scriptsize (function)}}\\


 Computes the degree of the vertex \mbox{\texttt{v}} of the directed graph \mbox{\texttt{DG}} 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> G:=RandomDiGraph(4);
  [ [ 1 ], [ 1, 2, 4 ], [  ], [ 1, 2, 3 ] ]
  gap> AutoVertexDegree(G,2);
  5
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{ReversedGraph}}
\logpage{[ "A", 1, 5 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{ReversedGraph( G )\index{ReversedGraph@\texttt{ReversedGraph}}
\label{ReversedGraph}
}\hfill{\scriptsize (function)}}\\


 Computes the reversed graph of the directed graph G. It is the graph obtained
from G by reversing the edges. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> G:=RandomDiGraph(4);
  [ [  ], [ 4 ], [ 2 ], [ 1, 4 ] ]
  gap> ReverseD
      identifier has no completions
  gap> ReversedGraph(G);
  [ [ 4 ], [ 3 ], [  ], [ 2, 4 ] ]
\end{Verbatim}
 }

 We say that a digraph is connected when for every pair of vertices there is a
path consisting of directed or reversed edges from one vertex to the other. 

\subsection{\textcolor{Chapter }{AutoConnectedComponents}}
\logpage{[ "A", 1, 6 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{AutoConnectedComponents( G )\index{AutoConnectedComponents@\texttt{AutoConnectedComponents}}
\label{AutoConnectedComponents}
}\hfill{\scriptsize (function)}}\\


 Computes a list of the connected components of the digraph 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> G:=RandomDiGraph(6);
  [ [  ], [ 1, 4, 5, 6 ], [  ], [ 1, 3, 5, 6 ], [ 2, 3 ], [ 2, 4, 6 ] ]
  gap> AutoConnectedComponents(G);
  [ [ 1, 2, 3, 4, 5, 6 ] ]
\end{Verbatim}
 }

 Two vertices of a digraph belong to a strongly connected component if there is
a directed path from each one to the other.

 

\subsection{\textcolor{Chapter }{GraphStronglyConnectedComponents}}
\logpage{[ "A", 1, 7 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{GraphStronglyConnectedComponents( G )\index{GraphStronglyConnectedComponents@\texttt{GraphStronglyConnectedComponents}}
\label{GraphStronglyConnectedComponents}
}\hfill{\scriptsize (function)}}\\


 Produces the strongly connected components of the digraph \mbox{\texttt{G}}. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> G:=RandomDiGraph(6);
  [ [  ], [ 4 ], [  ], [ 4, 6 ], [  ], [ 1, 4, 5, 6 ] ]
  gap> GraphStronglyConnectedComponents(G);
  [ [ 1 ], [ 2 ], [ 3 ], [ 4, 6 ], [ 5 ] ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{UnderlyingMultiGraphOfAutomaton}}
\logpage{[ "A", 1, 8 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{UnderlyingMultiGraphOfAutomaton( A )\index{UnderlyingMultiGraphOfAutomaton@\texttt{UnderlyingMultiGraphOfAutomaton}}
\label{UnderlyingMultiGraphOfAutomaton}
}\hfill{\scriptsize (function)}}\\


 \mbox{\texttt{A}} is an automaton. The output is the underlying directed multi-graph. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> a:=RandomAutomaton("det",3,2);;Display(a);
     |  1  2  3
  --------------
   a |  1  3
   b |     2  3
  Initial state:    [ 1 ]
  Accepting states: [ 1, 2 ]
  gap> UnderlyingMultiGraphOfAutomaton(a);
  [ [ 1 ], [ 3, 2 ], [ 3 ] ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{UnderlyingGraphOfAutomaton}}
\logpage{[ "A", 1, 9 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{UnderlyingGraphOfAutomaton( A )\index{UnderlyingGraphOfAutomaton@\texttt{UnderlyingGraphOfAutomaton}}
\label{UnderlyingGraphOfAutomaton}
}\hfill{\scriptsize (function)}}\\


 \mbox{\texttt{A}} is an automaton. The output is the underlying directed graph. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> a:=RandomAutomaton("det",3,2);;Display(a);
     |  1  2  3
  --------------
   a |     1  2
   b |  1  2
  Initial state:   [ 2 ]
  Accepting state: [ 2 ]
  gap> UnderlyingGraphOfAutomaton(a);
  [ [ 1 ], [ 1, 2 ], [ 2 ] ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{DiGraphToRelation}}
\logpage{[ "A", 1, 10 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{DiGraphToRelation( D )\index{DiGraphToRelation@\texttt{DiGraphToRelation}}
\label{DiGraphToRelation}
}\hfill{\scriptsize (function)}}\\


 Returns the relation corresponding to the digraph. Note that a directed graph
may be seen in a natural way as a binary relation on the set of vertices. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> G:=RandomDiGraph(4);
  [ [  ], [  ], [ 4 ], [ 4 ] ]
  gap> DiGraphToRelation(G);
  [ [ 3, 4 ], [ 4, 4 ] ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{MSccAutomaton}}
\logpage{[ "A", 1, 11 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{MSccAutomaton( A )\index{MSccAutomaton@\texttt{MSccAutomaton}}
\label{MSccAutomaton}
}\hfill{\scriptsize (function)}}\\


 Produces an automaton where, in each strongly connected component, edges
labeled by inverses are added. (M stands for modified.) 

 This construction is useful in Finite Semigroup Theory. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> a:=RandomAutomaton("det",3,2);;Display(a);
     |  1  2  3
  --------------
   a |  1  3
   b |  2  3
  Initial state:    [ 1 ]
  Accepting states: [ 1, 2, 3 ]
  gap> MSccAutomaton(a);
  < deterministic automaton on 4 letters with 3 states >
  gap> Display(last);
     |  1  2  3
  --------------
   a |  1  3
   b |  2  3
   A |  1
   B |
  Initial state:    [ 1 ]
  Accepting states: [ 1, 2, 3 ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{AutoIsAcyclicGraph}}
\logpage{[ "A", 1, 12 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{AutoIsAcyclicGraph( G )\index{AutoIsAcyclicGraph@\texttt{AutoIsAcyclicGraph}}
\label{AutoIsAcyclicGraph}
}\hfill{\scriptsize (function)}}\\


 The argument is a graph's list of adjacencies and this function returns true
if the argument is an acyclic graph and false otherwise. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> RandomDiGraph(3);
  [ [  ], [ 3 ], [ 2 ] ]
  gap> AutoIsAcyclicGraph(last);
  false
\end{Verbatim}
 }

 }

 }


\chapter{\textcolor{Chapter }{ Drawing automata }}\logpage{[ "B", 0, 0 ]}
{
  The drawing of graphs described here uses \texttt{graphviz} \cite{KoutsofiosNorth:2002}, a software for drawing graphs developed at AT  \&   T Labs, that can be obtained at \texttt{http://www.graphviz.org/}. 
\section{\textcolor{Chapter }{ Installing some external programs }}\logpage{[ "B", 1, 0 ]}
{
  If you work under \texttt{LINUX}, you should install \texttt{graphviz}. }

 
\section{\textcolor{Chapter }{ Functions to draw automata }}\logpage{[ "B", 2, 0 ]}
{
  

\subsection{\textcolor{Chapter }{DrawAutomaton}}
\logpage{[ "B", 2, 1 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{DrawAutomaton( A[, file] )\index{DrawAutomaton@\texttt{DrawAutomaton}}
\label{DrawAutomaton}
}\hfill{\scriptsize (function)}}\\


 This function draws automaton \texttt{A}. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> x:=Automaton("det",3,2,[ [ 2, 3, 0 ], [ 0, 1, 2 ] ],[ 1 ],[ 1, 2, 3 ]);;
  gap> DrawAutomaton(x,"exx");
  Displaying file: /tmp/tmp.LKoc7O/exx.dot.ps
\end{Verbatim}
 The output would be the following diagram displayed in a \emph{ghostview} window. 

  \begin{figure}[htbp] \begin{center} \leavevmode \includegraphics[bb=0 0 132
304]{aut2} \end{center} \label{fig:aut2} \end{figure}   

 }

 

\subsection{\textcolor{Chapter }{DrawAutomata}}
\logpage{[ "B", 2, 2 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{DrawAutomata( A, B[, file] )\index{DrawAutomata@\texttt{DrawAutomata}}
\label{DrawAutomata}
}\hfill{\scriptsize (function)}}\\


 This function tests if automaton \texttt{ A } is a subautomaton of \texttt{ B } in which case draws \texttt{ B } highlighting the edges not in \texttt{ A } by drawing them in a dotted style, while the others are drawn in a plain
style. }

 

\subsection{\textcolor{Chapter }{DrawGraph}}
\logpage{[ "B", 2, 3 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{DrawGraph( G[, file] )\index{DrawGraph@\texttt{DrawGraph}}
\label{DrawGraph}
}\hfill{\scriptsize (function)}}\\


 Draws a graph specified as an adjacency list \texttt{G}. }

 

\subsection{\textcolor{Chapter }{DrawSCCAutomaton}}
\logpage{[ "B", 2, 4 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{DrawSCCAutomaton( A[, file] )\index{DrawSCCAutomaton@\texttt{DrawSCCAutomaton}}
\label{DrawSCCAutomaton}
}\hfill{\scriptsize (function)}}\\


 Draws automaton \texttt{ A } and highlights it's strongly connected components by drawing the other edges
in a dotted style. }

 }

 }


\chapter{\textcolor{Chapter }{Inverse automata and subgroups of the free group}}\logpage{[ "C", 0, 0 ]}
{
 Inverse automata with a single initial/accepting state are in a one to one
correspondence with finitely generated subgroups of the free group over the
alphabet of the automaton. See \cite{MSW:2001}, \cite{KM:2002} for details, as well as for concepts such as \emph{flower automaton} and \emph{Stallings foldings}. 
\section{\textcolor{Chapter }{From subgroups to inverse automata}}\logpage{[ "C", 1, 0 ]}
{
 A finitely generated subgroup of a finitely generated free group is given
through a list whose first element is the number of generators of the free
group and the remaining elements are the generators of the subgroup. The set
of generators of the free group of rank $n$ consists on the $n$ first letters of the set $\{a,b,c,d,e,f,g\}$. In particular, free groups of rank greater than $8$ must not be considered. A formal inverse of a generator is represented by the
corresponding capital letter. 

 A generator of the subgroup may be given through a string of letters or
through a list of positive integers as should be clear from the example that
follows. 

 For example, \texttt{[2,"abA","bbabAB"]} stands for the subgroup of the free group of rank 2 on the generators $aba^{-1}$ and $bbaba^{-1}b^{-1}$. The same subgroup may be given as \texttt{[2,[1,2,3],[2,2,1,2,3,4]]}. The number $ n+j$ represents the formal inverse of the generator represented by $j$. One can go from one representation to another, using the following
functions. 

\subsection{\textcolor{Chapter }{GeneratorsToListRepresentation}}
\logpage{[ "C", 1, 1 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{GeneratorsToListRepresentation( L )\index{GeneratorsToListRepresentation@\texttt{GeneratorsToListRepresentation}}
\label{GeneratorsToListRepresentation}
}\hfill{\scriptsize (function)}}\\


 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> L:=[2,"abA","bbabAB"];;
  gap> GeneratorsToListRepresentation(L);
  [ 2, [ 1, 2, 3 ], [ 2, 2, 1, 2, 3, 4 ] ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{ListToGeneratorsRepresentation}}
\logpage{[ "C", 1, 2 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{ListToGeneratorsRepresentation( K )\index{ListToGeneratorsRepresentation@\texttt{ListToGeneratorsRepresentation}}
\label{ListToGeneratorsRepresentation}
}\hfill{\scriptsize (function)}}\\


 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> K:=[2,[1,2,3],[2,2,1,2,3,4]];;
  gap> ListToGeneratorsRepresentation(K);
  [ 2, "abA", "bbabAB" ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{FlowerAutomaton}}
\logpage{[ "C", 1, 3 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{FlowerAutomaton( L )\index{FlowerAutomaton@\texttt{FlowerAutomaton}}
\label{FlowerAutomaton}
}\hfill{\scriptsize (function)}}\\


 The argument \texttt{L} is a subgroup of the free group given through any of the representations
described above. Returns the flower automaton. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> W:=[2,"bbbAB","abAbA"];;
  gap> A:=FlowerAutomaton(W);
     |  1          2       3       4    5       6       7    8       9
  ---------------------------------------------------------------------
   a | [ 6, 9 ]                        [ 4 ]                [ 7 ]
   b | [ 2, 5 ]   [ 3 ]   [ 4 ]                [ 7 ]        [ 9 ]
  Initial state:   [ 1 ]
  Accepting state: [ 1 ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{FoldFlowerAutomaton}}
\logpage{[ "C", 1, 4 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{FoldFlowerAutomaton( A )\index{FoldFlowerAutomaton@\texttt{FoldFlowerAutomaton}}
\label{FoldFlowerAutomaton}
}\hfill{\scriptsize (function)}}\\


 Makes identifications on the flower automaton \texttt{A}. In the literature, these identifications are called Stallings foldings. 

 (This function may have \texttt{true} as a second argument. WARNING: the second argument should only be used when
facilities to draw automata are available. In that case, one may visualize the
identifications that are taking place.) 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> B := FoldFlowerAutomaton(A);
     |  1  2  3  4  5  6  7
  --------------------------
   a |  5  4              6
   b |  2  3  4     6     5
  Initial state:   [ 1 ]
  Accepting state: [ 1 ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{SubgroupGenToInvAut}}
\logpage{[ "C", 1, 5 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{SubgroupGenToInvAut( L )\index{SubgroupGenToInvAut@\texttt{SubgroupGenToInvAut}}
\label{SubgroupGenToInvAut}
}\hfill{\scriptsize (function)}}\\


 Returns the inverse automaton corresponding to the subgroup given by \mbox{\texttt{L}}. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> L:=[2,"bbbAB","AbAbA"];;
  gap> SubgroupGenToInvAut(L);
     |  1  2  3  4  5  6  7  8
  -----------------------------
   a |  8  4        1     6
   b |  2  3  4     6     8
  Initial state:   [ 1 ]
  Accepting state: [ 1 ]
  
\end{Verbatim}
 }

 }

 
\section{\textcolor{Chapter }{From inverse automata to subgroups}}\logpage{[ "C", 2, 0 ]}
{
 Given an inverse automaton with a single initial/accepting state, one can find
a set of generators for the subgroup represented by the automaton. Moreover,
using a geodesic tree, one can find a Nielsen reduced set of generators \cite{KM:2002}. 

\subsection{\textcolor{Chapter }{GeodesicTreeOfInverseAutomaton}}
\logpage{[ "C", 2, 1 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{GeodesicTreeOfInverseAutomaton( A )\index{GeodesicTreeOfInverseAutomaton@\texttt{GeodesicTreeOfInverseAutomaton}}
\label{GeodesicTreeOfInverseAutomaton}
}\hfill{\scriptsize (function)}}\\


 Returns a subautomaton of \mbox{\texttt{A}}whose underlying graph is a geodesic tree of the underlying graph of the
inverse automaton \texttt{A}. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> A:=Automaton("det",4,2,[ [ 3, 4, 0, 0 ], [ 2, 3, 4, 0 ] ],[ 1 ],[ 1 ]);;
  gap> G := GeodesicTreeOfInverseAutomaton(A);
     |  1  2  3  4
  -----------------
   a |  3
   b |  2     4
  Initial state:   [ 1 ]
  Accepting state: [ 1 ]
\end{Verbatim}
 }

 

\subsection{\textcolor{Chapter }{InverseAutomatonToGenerators}}
\logpage{[ "C", 2, 2 ]}\nobreak
{\noindent\textcolor{FuncColor}{$\Diamond$\ \texttt{InverseAutomatonToGenerators( A )\index{InverseAutomatonToGenerators@\texttt{InverseAutomatonToGenerators}}
\label{InverseAutomatonToGenerators}
}\hfill{\scriptsize (function)}}\\


 Returns a set of generators (given trough the representation above) of the
subgroup of the free group corresponding to the automaton \texttt{A} given. 
\begin{Verbatim}[fontsize=\small,frame=single,label=Example]
  gap> NW := InverseAutomatonToGenerators(A);
  [ 2, "baBA", "bbA" ]
\end{Verbatim}
 }

 }

 }

\def\bibname{References\logpage{[ "Bib", 0, 0 ]}}

\bibliographystyle{alpha}
\bibliography{AutMan}

\def\indexname{Index\logpage{[ "Ind", 0, 0 ]}}


\printindex

\newpage
\immediate\write\pagenrlog{["End"], \arabic{page}];}
\immediate\closeout\pagenrlog
\end{document}
