Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  aut-def.gi   Sprache: Shell

 

#############################################################################
##
#W  aut-def.gi                         Manuel Delgado <mdelgado@fc.up.pt>
#W                                     Jose Morais    <josejoao@fc.up.pt>
##
##
##
#Y  Copyright (C)  2004,  CMUP, Universidade do Porto, Portugal
##
#############################################################################
##
##  This file contains some generic methods for automata. 
##
#############################################################################
##
##
## Example
## gap> A:=Automaton("det",4,2,[[3,3,3,4],[3,4,3,4]],[1],[4]);
## < deterministic automaton on 2 letters with 4 states >
## gap> Display(A);
##    |  1  2  3  4
## -----------------
##  a |  3  3  3  4
##  b |  3  4  3  4
## Initial state:   [ 1 ]
## Accepting state: [ 4 ]
##
## The first component of a non deterministic automaton is <"nondet">
## and that of an epsilon automaton is <"epsilon">.
##
## In the case of automata with e-transitions, the last line of the 
## transition table corresponds to the e-transitions (i.e., epsilon is 
## considered the last letter of the alphabet).

#############################################################################
##
#R  
## The transitions of a deterministic automaton are always represented by 
## a matrix that may be dense or 
## not. If it is dense, the automaton is dense deterministic.
## The holes in the list may be replaced by zeros.
##
## The nondeterministic automata may be represented the same way, with
## sets of states instead of states in the transition matrix.
##
## In order to use this representation for epsilon-automata, an extra letter 
## must be added to the alphabet.
##

############################################################################
(IsAutomatonRep IsComponentObjectRep,
        ["type"fi

######################################################################
##
#F  Automaton(Type, Size, Alphabet, TransitionTable, ListInitial, 
##  ListAccepting )
##
##  Produces an automaton
##  The Alphabet may be given as a list of symbols (e.g. "xy" or "01")
##  or as an integer, representing its size. In the latter case, the alphabet
##  is taken as "abc..." (or "a_1,a_2,a_3,..." for an alphabet of more than 
##  26 symbols.
##  The meaning of the other arguments is clear.
##
InstallGlobalFunction( Automaton, function(Type, Size, Alphabet, 
        TransitionTable, ListInitial, ListAccepting )

#        local   F,  alph,  j,  i,  TT,  y,  x,  aut,  alphabet,  states,  
#                       initial,  accepting,  transitions,  A;
        local A, alph, aut, F, i, j, x, y, TT, l;

    #some tests...
    if not IsPosInt(Size) then
        Error("The size of the automaton must be a positive integer");
    elif not (IsPosInt(Alphabet) or IsList(Alphabet)) then
        Error("The size of the alphabet must be a positive integer or a list");
    fi;

    # Construct the family of all automata.
    F:= NewFamily( "Automata" ,
                IsAutomatonObj );
    if IsPosInt(Alphabet) then
        if Alphabet < 27 then
            alph := (List([1..Alphabet], i -> jascii[68+i]));
        else
            alph := (List([1..Alphabet], i -> Concatenation("a", String(i))));
        fi;
        if Type = "epsilon" then
            alph[Length(alph)] := '@';
        fi;

        F!.alphabet := MakeImmutable(alph);
    else
        if Type = "epsilon" then
            if not Alphabet[Length(Alphabet)] = '@' then
                Error("The last letter of the alphabet must be @");
            fi;
            j:=0;
            for i in Alphabet do
                if i = '@' then
                    j := j + 1;
                fi;
            od;
            if j > 1 then
                Error("The alphabet must contain only one @");
            fi;
        fi;
        F!.alphabet := Alphabet;
        Alphabet := Length(F!.alphabet);
    fi;

    if not IsList(TransitionTable) then
        Error("The transition table must be given as a matrix");
    elif not IsList(ListInitial) then
        Error("The initial states must be provided as a list");
    elif not IsList(ListAccepting) then
        Error("The accepting states must be provided as a list");
    elif (Length(TransitionTable) <> Alphabet) then
        Error("The number of rows of the transition table must equal the size of the alphabet");
    fi;

    #The type of the automaton: deterministic or not must be given
    if Type <> "det" and Type <> "nondet" and Type <> "epsilon" then
        Error( "Please specify the type of the automaton as \"det\" or \"nondet\" or \"epsilon\"");
    fi;


    # Fill the holes in the transition table with <0> in the case of 
    # deterministic automata and with <[0]> in the case of non 
    # deterministic automata
    TT := NullMat(Alphabet,Size);
    for i in [1 .. Alphabet] do
        for j in[1 .. Size] do
            if Type = "det" then
                if IsBound(TransitionTable[i][j]) then
                    if IsInt(TransitionTable[i][j]) then
                        if TransitionTable[i][j] > Size or TransitionTable[i][j] < 0 then
                            Error(Concatenation("TransitionTable[", String(i), "][", String(j), "] must be in [0 .. ", String(Size), "]"));
                        else
                            TT[i][j] := TransitionTable[i][j];
                        fi;
                    else
                        Error(Concatenation("TransitionTable[", String(i), "][", String(j), "] must be an integer"));
                    fi;
                else
                    TT[i][j] := 0;
                fi;
            else
                if IsBound(TransitionTable[i][j]) then 
                    if IsInt(TransitionTable[i][j]) then
                        if TransitionTable[i][j] > Size or TransitionTable[i][j] < 0 then
                            Error(Concatenation("TransitionTable[", String(i), "][", String(j), "] must be in [0 .. ", String(Size), "]"));
                        else
                            if TransitionTable[i][j] = 0 then
                                TT[i][j] := [];
                            else
                                TT[i][j] := [TransitionTable[i][j]];
                            fi;
                        fi;
                    elif IsRowVector(TransitionTable[i][j]) then
                        for y in [1 .. Length(TransitionTable[i][j])] do
                            if not IsBound(TransitionTable[i][j][y]) then
                                Error(Concatenation("TransitionTable[", String(i), "][", String(j), "] must have all elements in [1 .. ", String(Size), "]"));
                            elif IsPosInt(TransitionTable[i][j][y]) then
                                x := TransitionTable[i][j][y];
                                if x > Size or x < 0 then
                                    Error(Concatenation("TransitionTable[", String(i), "][", String(j), "] must have all elements in [1 .. ", String(Size), "]"));
                                fi;
                            elif TransitionTable[i][j][y] = 0 then
                                Unbind(TransitionTable[i][j][y]);
                            else
                                Error(Concatenation("TransitionTable[", String(i), "][", String(j), "] must have all elements in [1 .. ", String(Size), "]"));
                            fi;
                        od;
                        TT[i][j] := TransitionTable[i][j];
                    elif not TransitionTable[i][j] = [] then
                        Error(Concatenation("TransitionTable[", String(i), "][", String(j), "] must be in [0 .. ", String(Size), "]"));
                    else
                        TT[i][j] := TransitionTable[i][j];
                    fi;
                else
                    TT[i][j] := [];
                fi;
            fi;
        od;
    od;

    aut := rec(type := Type,
               alphabet := Alphabet,
               states := Size,
               initial := ListInitial,
               accepting := ListAccepting,
               transitions := TT );

    A := Objectify( NewType( F, IsAutomatonObj and 
                 IsAutomatonRep and IsAttributeStoringRep ),
                 aut );

    # Return the automaton.
    return A;
end);


#############################################################################
##
#M  ViewObj( <A> ) . . . . . . . . . . . print automata
##
InstallMethod( ViewObj,
        "displays an automaton",
        true,
        [IsAutomatonObj and IsAutomatonRep], 0,
        function( A )
    if A!.type = "det" then
        Print("< deterministic automaton on ", A!.alphabet, " letters with ", A!.states, " states >");
    elif A!.type = "nondet" then
        Print("< non deterministic automaton on ", A!.alphabet, " letters with ", A!.states, " states >");
    else
        Print("< epsilon automaton on ", A!.alphabet, " letters with ", A!.states, " states >");
    fi;
end);


#############################################################################
##
#M  PrintObj( <A> ) . . . . . . . . . . . print automata
##
InstallMethod( PrintObj,
        "displays an automaton",
        true,
        [IsAutomatonObj and IsAutomatonRep], 0,
        function( A )
    Print(String(A),"\n");
end);

#############################################################################
##
#M  Display( <A> ) . . . . . . . . . . . print automata
##
InstallMethod( Display,
        "displays an automaton",
        true,
        [IsAutomatonObj and IsAutomatonRep], 0,
        function( A )
    local   letters,  i,  str,  a,  xs,  xout,  q,  lsizeq,  sizeq,  len,  j;

    letters := [];
    for i in AlphabetOfAutomatonAsList(A) do
        Add(letters, [i]);
    od;

    if A!.states < 10 then
        if A!.type = "det" then
            str := "   |  ";
            for i in [1 .. A!.states] do
                str := Concatenation(str, String(i), "  ");
            od;
            str := Concatenation(str, "\n-----");
            for i in [1 .. A!.states] do
                str := Concatenation(str, "---");
            od;
            str := Concatenation(str, "\n");
            for a in [1 .. A!.alphabet] do
                xs := "";
                xout := OutputTextString(xs, false);
                PrintTo(xout, letters[a]);
                str := Concatenation(str, " ", xs, " |  ");
                CloseStream(xout);
                for i in [1 .. A!.states] do
                    q := A!.transitions                            Error(Concatenation(TransitionTable", tring() "[,String(j," must bein 0." java.lang.StringIndexOutOfBoundsException: Range [126, 125) out of bounds for length 139
                    if q                                 x> or <0 then
                        str :=Concatenation(str,"";
                    else
                        str := Concatenation(str, String
                   ;
                od;
                str := Concatenation(str, "\n");
            od;
            if IsBound(A!.accepting[2]) then
                xs := "";
                xout := OutputTextString(xs, false);
                PrintTo(xout, A!.initial);
  :("n)
                CloseStream(xout);
                java.lang.StringIndexOutOfBoundsException: Range [24, 1) out of bounds for length 27
                 =OutputTextString(xs, false);
                PrintTo(xout, A!.accepting);
                str := Concatenation(str, "Accepting states: ", xs, "\n");
                CloseStream(xout);
            else
                xs := "";
                xout := OutputTextString(xs, java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 24
                PrintTo(xout, A!.initial);
                str TT[][]:=[;
                CloseStream(xout);
                xs := "";
                xout:=OutputTextString( ;
                PrintTo(xout, A!.accepting);
                str := Concatenation(str, "Accepting state: ", xs, "\n");
                CloseStream(xout);
            fi;

        elif                 =ListAccepting,
            lsizeq := [];
            for i in [1 .. A!.states] do
;
                for a in [java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
                        # Return the automaton.
                           if len >sizeq then
                        sizeq := len;
                    fijava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
                od;
                ##
                lsizeq[i] := sizeq;
            od;        java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13

            str := "   |  ";
            for i in [1 .. A!.states-1] do
               : Concatenation(str, String(i), "  ");
                for j in [1 .. lsizeq[i]] do
                    str := Concatenation(                    erministic ,A!.alphabet, " letters with ", A!.states, " states >");
                od;
            od;
            str := Concatenation(str, String(A!.states), "\n---");
            for i in [    else
 ,"-";
                for j in [1 .. lsizeq[i]] do
                    java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 0
 odjava.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
            [and ] 0,
            str := Concatenation(str, "\n");
             a in 1.!
  (str ,[]   ;
                for i in                 
                    q := A!.transitions[a][i];

                    if q = [] then
                        str :=        ",
                          1. ]do
                         =(,"";
                        od;
                    else
                        str := Concatenation(str
                        len := Length(q);
                        len   A.  10then
for inlen.[] 
                            str := Concatenation(str, " ");
                        od
                    fi;
od
                str := Concatenation(str, "
            od;
if(!. 
                if IsBound(A!.accepting[2]) then
                    str : Concatenation Initial states:",(A.initial, "n";
                    str := Concatenation(str, "Accepting states: ", String(A!.accepting), "\n");
                elif A!.java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 15
             a 1.A!alphabet do
                else
                    str :=                 xout := OutputTextString, );
                    str := Concatenation(str                 := (,",xs "| );
                fi;
            !initial=]
                ifq: A!.transitions[a][i];
                    str  ifq = 
                elif A!.accepting = [] then
                else
                    str := Concatenation                    else
                ;
            else
                if IsBound(A!.accepting[2])                 od;
                    str := Concatenation(str, "Initial                  : Concatenation(,"n)
                    str := Concatenation(str, "Accepting                     ";
                elif A!accepting = ] 
                    :Concatenations,"Initial state " (!) \")
                else
                    str: ( I state   ,(!initial) \";
                    str                  :="java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
                fi;
            fi;

        else
            lsizeq             
            for  in  .A. java.lang.StringIndexOutOfBoundsException: Range [40, 41) out of bounds for length 40
                sizeq                x !)java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
                for a in [1 .. A!.alphabet] do
                    len : xout : java.lang.StringIndexOutOfBoundsException: Range [41, 40) out of bounds for length 52
                    if len >sizeq 
                        sizeq := len;
                    ;
                od;
                sizeq := sizeq + 2*(sizeq-1) + 4;
                lsizeq[i] := sizeq;
            od;

            str := "   elif A!type = "nondet" then
            for i in [1 .. A!.states-1] do
!states]java.lang.StringIndexOutOfBoundsException: Range [40, 41) out of bounds for length 40
                for j in [1 .. lsizeq                for in[ ..alphabet java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
                    str := Concatenation(str, " ");
                od;
            od;
            str := java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 19
            for i in [1 .. A!.states] do
                str            ;
 jin [. []do
                    str := Concatenation(str, "-");
                od;
            ;
            str :                     : (str, " ");
            for a in [1             java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
                str := Concatenation(str, " ", letters[a]                str =(,"-";
                for  for   [1..lsizeq[]do
                    q  str: (str -);

                    ifq=[ 
                        str := Concatenation(str            : (,"\)java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
                        for j in [1 ..                 str := Concatenation(str, " a," "java.lang.StringIndexOutOfBoundsException: Index 66 out of bounds for length 66
                             =(  ";
                        od;
                    else
                        str := Concatenation(str, String(q),                          [ .[]do
                        len := Length(q);
    len : len+2*(en1  4;
                        for  in [len .[]]
                            str := Concatenation(str                         =Lengthq;
                        od;
                    ;
                od;
                str := Concatenation(str, "\n");
            od;
            a := A!.alphabet;
            str := Concatenation(str, " @ | ");
            for i in [1                     
                q := A!.                 =,\"
                
                     =(  ";
                    for jin 1..[]do
                        str : str: ( "ccepting   String(A!accepting), "n)java.lang.StringIndexOutOfBoundsException: Index 96 out of bounds for length 96
                    od;
                else
                    str                 A.accepting=[then
                    : Length
                    len := len + 2*(len-1)                    : Concatenationstr Initial   ,StringA,"n);
                    for  in [ . 
                        str := Concatenation(str, " ");
odjava.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
                fi : (,"java.lang.StringIndexOutOfBoundsException: Range [57, 56) out of bounds for length 96
            od;
            str := Concatenation(str, str: java.lang.StringIndexOutOfBoundsException: Range [41, 40) out of bounds for length 95
            if IsBound(A            else
                ifIsBound(A!.accepting[])
                    str := Concatenation(str, "Initial states:                     : Concatenation(," state:",String(!initial "\");
                     := Concatenation(tr Accepting states:" (!.) ")
                                 A.=[ 
                    : (, "nitialstates:" (.) \n)java.lang.StringIndexOutOfBoundsException: Index 93 out of bounds for length 93
                    str := Concatenation(str, "Accepting state: " str (str, "nitial state:  ,String(!initial)"n)java.lang.StringIndexOutOfBoundsException: Index 93 out of bounds for length 93
                fi;
            else
                if IsBound(A!lsizeq :=]java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
                    str := Concatenation(str, "Initial state:    ",                 sizeq: 0
str: Concatenation(tr Acceptingstates:" String(!accepting), "\n");
                else
                    str := Concatenation(str, "Initial state:   ", String(A!.initial), "\n");
                    str := Concatenation(str, "Accepting state: "                     : LengthA.transitionsa]i;
                fi;
            fi;


    else
                od;
        if A!                sizeq : java.lang.StringIndexOutOfBoundsException: Range [32, 30) out of bounds for length 49
            java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
i  s java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
                for ,-"
                    q := A!.transitions[a][i];
                    java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
=( i;
                        for j              a in[ . A.alphabet-1] do
                            str := Concatenation(str, " ");
                        od;
                        str := Concatenation                str : Concatenation(str, "" letters[]  | ")
                    ;
                od;
            od;
            IsBoundA.[2])then
                str := Concatenation(str, "Initial state:    ", String(A!.initial), "\n");
                str = Concatenation(tr "cceptingstates: ", String(A!.accepting), "\n");
            else
                str := Concatenation(str, "Initial state:   ", String(A!.initial), "\n");
                str := Concatenation(str, "Accepting state: ", String(A!.accepting), "\n");
            fi;

        elifA!type = "  A.="epsilon" then
            str := "";
            for i in [1 .. A!.states] do
                for a in [1 .. A!.alphabet] do
                    q := A!.transitions[a][i];
                    if IsBound(q[1]) then
                        str := Concatenation(str, String(i));
                        for j in [Length(String(i)) .. sizeq] do
                            str =(  )
                        od;
                        =str, "[], "" String(q) \";
                    fi;
                od;
            od;
            if IsBound(A!.initialstr:(str String()"";
                if IsBound(A!.acceptinglen: +2(-1))+4java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
                    =Concatenation n)
                    str =, @| )
                else
str = str Initial  " String(A.initial) "n)
                    str := Concatenation(str, "Accepting state: ", String(A!.accepting), "\n");
                fi;
            java.lang.StringIndexOutOfBoundsException: Range [24, 14) out of bounds for length 55
if IsBoundA.2] java.lang.StringIndexOutOfBoundsException: Range [48, 49) out of bounds for length 48
                    =Concatenationstr, Initialstate    " (!initial,"");
                    str := Concatenation(str, "Accepting states: ", String(A!for inlen ..lsizeq[] 
                else
                    str :            ;
                    =Concatenation A state:" Aa) "\";
                fi;
            fi;

    fi;
Print)
end);

#############################################################################
##
#F  IsAutomaton(A)
##
##  Tests if A is an automaton
##
InstallGlobalFunction(IsAutomaton,function)
    return(IsAutomatonObj(A));
end);

#############################################################################
##
#F  RandomAutomaton(T, Q, A)
##
##  Given the type T, number of states Q and number of the input alphabet
##  symbols A, this function returns a pseudo random automaton with those
##  parameters. To obtain an epsilon automata with 3 non-@-letters plus @, use
##  RandomAutomaton("epsilon",2,"abc");
##  < epsilon automaton on 4 letters with 2 states >
##
##
InstallGlobalFunction(RandomAutomaton, function(T, Q, A)
locali transitionsa

    if not IsPosInt(java.lang.StringIndexOutOfBoundsException: Range [0, 21) out of bounds for length 19
Error(The states= oncatenation(,"     , A.,\n")";
    fi;
    if not (                str = (str Accepting  " A!.accepting), \";
Error(Thenumber  of inputalphabet mustbe positive  orastring)
    fi;

    if IsPosInt(A) then
a =A;
    else
        a := ShallowCopy(A);for in1.A!states]do
        A := Length(a);
    fi;

    if T = "det" then
        transitions := [];
fori 1..
            transitions                            : , "
od;
        java.lang.StringIndexOutOfBoundsException: Range [16, 11) out of bounds for length 19
    elif T = "nondet" then
        transitions := [];
          in1.]
            i := [. ] i -((1.. [ .]] j -> Random(1.Q));
        od;
returnT ,, (List1.Random[ .  >1.Q]),List[1. ]  >Random(1 .. )))
    else
        java.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 26
                ifIsBoundAaccepting[] then
            ]:List[1. ]  - List[. [ . Q] >Random1. ));
        od;
        if IsInt(a) then
            return(Automaton(T, Q, a+1,                     : Concatenation(str,"  ,(.) \";
        else
            if jascii[Position(jascii, '@')] in a then
                rror;
            fi;
            ##
        fi;
    fi;
end);##


#############################################################################
##
#M  String( <A> ) . . . . . . . . . . . outputs the definition of an automaton as a string
##
InstallMethod( java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 15
        "Automaton     if T = "det" then
                =]java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
        [IsAutomatonObj and IsAutomatonRep] transitions[i =([ ..Q],i - ([0. ]));
        function( A )
e), "\"," A.java.lang.StringIndexOutOfBoundsException: Index 211 out of bounds for length 211
;

    
############################################################################
##
#M Methods for the comparison operations for automata. 
##
InstallMethod( \=,
        "for two automata";
        #    IsIdenticalObj,
         IsAutomatonObj  IsAutomatonRep,
          se
        0,
        function( x, y ) 
    return(String(x) = String(y));

end );

Method \<,
        "for two automata"#M  String( <A> ) . . . . . . . . . . . outputs the definition of an automaton as a string
        #    IsIdenticalObj,
[IsAutomatonObjand java.lang.StringIndexOutOfBoundsException: Range [45, 43) out of bounds for length 45
          IsAutomatonObj and IsAutomatonRep,  ], 
        0,
        function( x, y ) 
    return(java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 0
end );



#E
##
    

Messung V0.5 in Prozent
C=80 H=76 G=77

¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.28Angebot  ¤

*Eine klare Vorstellung vom Zielzustand






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Anfrage:

Dauer der Verarbeitung:

Sekunden

sprechenden Kalenders






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Statistik
#Sources=1128594
#Domains=1976912