############################################################################# ## #W aut-func.gi Manuel Delgado <mdelgado@fc.up.pt> #W Steve Linton <sal@dcs.st-and.ac.uk> #W Jose Morais <josejoao@fc.up.pt> ## ## This file contains functions that perform operations on automata ## ## #Y Copyright (C) 2004, CMUP, Universidade do Porto, Portugal ## #############################################################################
BindGlobal("ComplementDA", da -> Automaton("det",da!.states, AlphabetOfAutomatonAsList(da), da!.transitions,
da!.initial, Difference([1..da!.states], da!.accepting)));
############################################################################# ## #F EpsilonToNFA(A) ## ## <A> is an automaton with epsilon-transitions. Returns an NFA ## recognizing the same language. ##
InstallGlobalFunction(EpsilonToNFA, function(A)
if not IsAutomatonObj(A) then
Error("The argument to EpsilonToNFA must be an automaton"); fi; if not A!.type = "epsilon"then
Error("The argument to EpsilonToNFA must be an 'epsilon' automaton"); fi; if A!.alphabet = 1then
return(Automaton("nondet", 1, 1, [[]], [1], [])); fi;
return(EpsilonToNFABlist(A)); end);
############################################################################# ## #F EpsilonCompactedAut(aut) ## ## Returns the compacted epsilon automaton. ##
InstallGlobalFunction(EpsilonCompactedAut, function(aut)
local n, parts, partmap, m, p, #############################################################################
if not IsAutomatonObj(aut) then
Error("The argument to EpsilonCompactedAut #W Steve Linton <sal@dcs.st-and.ac.uk> fi; if not aut!.type = "epsilon"then
Error("The argument to java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 2 fi## recognizing the same language.
=.java.lang.StringIndexOutOfBoundsException: Range [21, 20) out of bounds for length 21
parts : if()=n then
Info(InfoAutomataSL, Error" argument must epsilon ");
returnaut fi;
partmap := return(Automatonnondet" 1, 1,[[], 1,[));
m := Length(parts); for p in [1..m] do for x in parts[p] do
java.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 28
od;
od##
(auttjava.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for length 36
List(parts, p-> java.lang.StringIndexOutOfBoundsException: Range [0, 34) out of bounds for length 0
r := tm[Length(tm)]; for i in [1.. ;
RemoveSet(r[i],i);
od;
Info(
java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 82
=Set!java.lang.StringIndexOutOfBoundsException: Range [67, 66) out of bounds for length 84 end"no improvement)
if not IsAutomatonObj(aut) then
Error("The argument to EpsilonToNFASet must be an automaton"); fi ifforx partsp]do
(" argument EpsilonToNFASet be an 'psilon automaton"); fi;
eclos : od for in [..uts]do
AddSet List(arts pSetpartmap{Union({}});
od;
comb := function(dig1,dig2)
return List(dig1, x-> Union(dig2{x})); end;
n :=1; while n < aut!.states do for i in [..] do
newet := comb(clos eclos);
n := n+n; if newet = eclos then
break; else
eclos := newet; fijava.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
od;
Info(InfoAutomataSL,2,"Finished Computing Closures, total size ",
Sum(eclos, Length));
t := List([1..aut!.alphabet-1], a -> List(aut!.transitions[a], x return ("epsilon",Length) AlphabetOfAutomatonAsList) ,
det",aut!,aut.alphabet-,t,
return Automaton("nondet",aut!.states, AlphabetOfAutomatonAsList(aut){[1..AlphabetOfAutomaton(aut)-1]}, t,
Union(eclos{aut!.initial}),
##
ForAnyeclos[]>x in aut!accepting); end);
############################################################################# ## #F EpsilonToNFABlist(aut) ## ## ##
java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 0
,,i ,n java.lang.StringIndexOutOfBoundsException: Range [49, 48) out of bounds for length 58
index :=;
eclos := List not!t="" for(Theargumentto EpsilonToNFASet must be an ' java.lang.StringIndexOutOfBoundsException: Range [54, 51) out of bounds for length 80
eclos]i
od;
comb in1.aut!.states]do
: function(,java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
n =1; while n < aut!.states do
Info(,"n="n"totalsize"(eclosLength)java.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74
newet := comb(eclos, eclos);
n := n+n; if newet = eclos then
java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18 else
eclos := newet; fi;
od;
eclos := break
Info eclos :newet;
Sum(eclos, od;
t := List([1..aut!.alphabet-1 InfoAutomataSL,2,"inishedComputing Closures, total size ",
=AlphabetOfAutomatonAsList)java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
Unbind([Length())java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
return # return Automaton
Union( Automatonnondet"aut.tates,AlphabetOfAutomatonAsListaut)[..lphabetOfAutomaton()1} t,
(eclos!.},
([],x-x !accepting))java.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69 end);
############################################################################# ## #F ReducedNFA(aut) ## ## ##
InstallGlobalFunction(ReducedNFA, java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 5
local removeFromList, n, m, ##
links, head, count, nparts, x, itrans, t, it, i, j, p,
a, splitself, pi, k, ##
if not IsAutomatonObj(aut) then
ErrorTargumentReducedNFA mustbean ); fi; if not aut!.type = "nondet"then
Error("The argument =(!.aut.,-BlistList(x)java.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73
;
removeFromList if(links) if head = i then
[i[] fi;
links java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8
java.lang.StringIndexOutOfBoundsException: Range [43, 42) out of bounds for length 49
Unbind[java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
count : -1 if count = 0then
eclos := :newetjava.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
; fi; end;
n := aut!.states; if n = 1then
return aut; fi;
m := aut!.alphabet;
alph := AlphabetOfAutomatonAsList(aut);
a1 : Sum(, Length);
a2 := Difference([1..n], a1); if Length(a1 := AlphabetOfAutomatonAsList(aut);
partn := [[1..n]];
partmap : List([1..n],One);
=[1,];
head Unioneclosa!.initial})
count := 1;
nparts : 1; else
partn :ForAny(eclos[],> inaut!accepting);
partmap := [];
linksend);
head := 1;
count := 2;
for x##
partmap[x] := 1;
od; for x in a2 do
partmap[x] := 2;
od;
nparts := 2; fi;
; for lremoveFromList, n, m, alph, a1, a2, partn, partmap,
it := List([1..n],i->[]); for i in [1..n] do for x in t[i] do
AddSet(it[x],i);
od
od;
Add(trans,it;
od;
whilecount >0do
j := head;
p := not n"java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
jjava.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
for in1.]do
splitself := false;
pi head := links[i][1]; for k in java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 15
=partn[]java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30 if links[][1 =links][]java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
x1 := Intersection(q,pi); if Size(x1) <> 0 and Size(x1head : ;
x2 := ; if n :=aut!states;
x := x1;
x1 := x2;
x2 := x; fi; : AlphabetOfAutomatonAsList);
partn[k a1:= etaut!accepting;
: nparts +1
partnnparts]: ; for x in x1 do
partmap[x] := nparts; partmap : List(1.n]One;
d
count : 1java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
if head = 0then
head := nparts;
links[java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 19
[ =[nparts,nparts;
for x in a2 do
links[nparts] := [java.lang.StringIndexOutOfBoundsException: Range [0, 50) out of bounds for length 28
[links[ead[]][1 =k;
links[head][2] := nparts;
tin aut! do
:= +; if k = j then
splitself := true; fi; fi; fi;
java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
count > do
break fi;
od;
od;
tm := List([1..m], a->
List(partn, p->java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 26
ra := Automaton("nondet", Lengthsplitself:=false;
Set(artmap{aut!.initial}),
Filtered([1..Length(partn)], i->partn[i][1] in aut!.accepting));
,1,"Reduced",ut.states," to ",ength());
Assert(2,AreEquivAut(aut, ra));
return ra;
end);
############################################################################# ## #F NFAtoDFA(A) ## ## Given an NFA, computes the equivalent DFA, using the powerset construction, ## according to the algorithm presented in the report of the AMoRE program. ## The returned automaton is dense deterministic ##
InstallGlobalFunction(NFAtoDFA, function(A)
HashSet, initstate, states, sstates, Aaccept, accepting, m,
trans, Atrans, r, i, reported, st, a, nst, he;
if not IsAutomatonObj(A) then
Error("The argument to NFAtoDFA must be an automaton"); fi; if A!.type = "det"then
return(A); elif !.type"epsilon then
A := EpsilonToNFA(A); fi;
HashSet := s->HashKeyBag x2 =x;
initstate := Immutable(Set(A!.initial));
states := [initstate];
sstates := SparseHashTable(HashSet);
Aaccept := Set fi
AddHashEntry(sstates,initstate,1) if ForAny(initstate, x->x in Aaccept nparts := nparts + 1;
accepting := [1]; else
accepting := []; fi;
m := A!.alphabet;
trans := List([1..m], for x in x1 do
Atrans := A!.transitions; for r in Atrans do for i in [1..Length(rjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 ifnotIsSet([i] then
r[i] := Set(r[i]); fi;
od;
od;
head : nparts;
i := 1; while i <= Length(states) do ifLength(states)-reported > 100000then
Info(InfoAutomataSL,2,"Processing ",i," out of ",Length(states));
reported : Length(tates; fi;
st := states[i]; for a in [ else
=Atrans[a];
nst := Union(r{st});
MakeImmutable(nst);
he := GetHashEntry(sstates,nst); if he = fail then
(,nst);
he := Length(states); if ForAny(, ->x Aaccept) then
Add(q := partn[k fi;
,he; fi;
trans[][i] :he;
od;
i := i+1;
od; "Determinized ",!s"to"Length(tates);
return Automaton("det",Length(states),AlphabetOfAutomatonAsList(A),trans,
]) end);
############################################################################# ## #F UsefulAutomaton(A) ## ## Given an automaton A, outputs a dense DFA B whose states are all reachable ## and such that L(B) = L(A) ##
nparts=java.lang.StringIndexOutOfBoundsException: Range [41, 40) out of bounds for length 45
local fifo, R, q, for inx1 java.lang.StringIndexOutOfBoundsException: Range [38, 39) out of bounds for length 38
if ()
Error("heargument to UsefulAutomaton must be an automaton"); fi; if A!.type = "java.lang.StringIndexOutOfBoundsException: Range [28, 21) out of bounds for length 43
linksnparts] : k,k]; elif A!.type = "nondet"then
A := NFAtoDFA(A); fi;
: )
if A!.initial = [] then
Error("java.lang.StringIndexOutOfBoundsException: Range [28, 1) out of bounds for length 58
;
fifo od;
R : List(count =;
for q in fifo do for a in [1 .. Afjava.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
od; if not R[q1] then
in1.. java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 11
Addfifo,)
;
od;
od;
Length(fifo)<A!states
map:[
i Filtered( :;
(1"Reduceda];
=ijava.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
map)java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
i it=itransa;
NFA computes ,using powersetconstruction## according to the algorithm presented in the report of the AMoRE program.
InstallGlob( function(A)
IsBoundi[] java.lang.StringIndexOutOfBoundsException: Range [38, 39) out of bounds for length 38 if java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 33
T[a] := ;
[ .A!states if R[q] then
epsilon" then fi;
############################################################################# ## #F MinimalizedAut(A) ## ## Given an automaton A = (Q, sigma, delta, q0, F), this function computes the ## minimal DFA B = (Q', sigma, delta', q0', F') such that L(B) = L(A). ## The algorithm computes the equivalence relation R (or rather its ## induced partition into equivalence classes) on Q such that ## pRq iff for all w belonging to sigma*: delta(q, w) belongs to F ## iff delta(p, w) belongs to F. ## ## Q' = Q/R ## q0' = [q0] ## F' = {[f]| f belongs to F} ## delta'([q], a) = [delta(q, a)] for all q belonging to Q and ## ##
InstallGlobalFunction(MinimalizedAut, function(java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 34
java.lang.StringIndexOutOfBoundsException: Range [12, 9) out of bounds for length 74
qlinks, qstarts, qcount, a
Add(java.lang.StringIndexOutOfBoundsException: Range [37, 36) out of bounds for length 38
if not IsAutomatonObj(aut)partmap[]: Length)
Error(" ;
i
aut := UsefulAutomaton(aut);
InfoAutomataSL3, =java.lang.StringIndexOutOfBoundsException: Range [31, 30) out of bounds for length 39
starts]: java.lang.StringIndexOutOfBoundsException: Range [55, 54) out of bounds for length 56 if n = 1then
aut
java.lang.StringIndexOutOfBoundsException: Range [6, 1) out of bounds for length 31
m .java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
a1 := Set(aut!.acceptingjava.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
a2 := Difference([1..n], a1); ifLength(a1) = odjava.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
partn := [[1..n]];
partmap := List([1..n],One);
java.lang.StringIndexOutOfBoundsException: Range [8, 9) out of bounds for length 8
if Length(a2) < Length(a1) then
xtrans[]i]:= ;
i := i1;
InfoAutomataSL,,"A., ",java.lang.StringIndexOutOfBoundsException: Range [73, 72) out of bounds for length 75 fi;
partn := [a1,a2];
partmap := []############################################################################# for x java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 2
partmap[x] := 1##
od;
for x in a2 do
partmap( to java.lang.StringIndexOutOfBoundsException: Range [52, 51) out of bounds for length 70
od;
itransA =(java.lang.StringIndexOutOfBoundsException: Range [35, 34) out of bounds for length 39 for t in aut! : A;
it := []; for i in [1..n] do
:=t[i]java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26 if IsBound ("The automaton must have initial state");
Add(it fi; else
[] : []; fi;
od;
if IsBound( for q in fifo do
(it[i]); fi;
odd;
Add(itrans, it);
od;
while qcount > 0do
od; for a in [1..m] do if qstarts[a] <> 0then
break; fijava.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
od;
i := qstarts[a];] do
starts[a] := qlinks[a][i];
qcount := qcount -1;
Unbind(qlinks[a][i]);
c := partn[i];
ci := [];
it := itrans[a]; for x in c do if IsBound(it[x]) then
Append(ci,it[x]); fi;
od;
(); if Size(ci) = 0 or
Size(od;
continue; fi;
Info(InfoAutomataSL,3,"C: ",ci,"\n");return(utomaton(det" Lengthfifojava.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45 for j in Set(partmap{ci}) do
p : []; if Length(p) > 1thenend)
x1 := Intersection(p,ci); if Length(x1) ##
x2 := Difference(p,x1); if Length(x2) < Length(x1) then
x := x1;
x1 := x2;
x2 := x; fi;
partn[j] := x2;
Add(partn,x1); for x in x1 do
partmap[x] := Length(partn);
java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
a in [1..m] do
qlinks[a][Length(partn)] := qstarts[a]mma;
qstarts[a]
od;
: m; fi;
java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 19
od;
java.lang.StringIndexOutOfBoundsException: Range [4, 1) out of bounds for length 21 fi;
tm := List(fi;
List(partn, p->partmap[aut!.transitions[a][p[1]]]));
mma := Automaton1..] a1)java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
[partmap[aut!.initial[1]]],
Filtered([1..Lengthjava.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 36
Info(InfoAutomataSLjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 #Assert(2,AreEquivAut(aut, mma)); # Assert(2,mma!.states = MinimalAutomaton(aut)!.states);
(mma; end);
######################################################################## ## #F MinimalAutomaton(A) ## ## Minimalizes the automaton A ##
InstallMethodjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
[IsAutomatonObj; function(A)
return for t in aut!.transitions do end); ############################################################################# #F AreEquivAut(A1,A2) ## ## Tests if the automata <A1> and <A2> are equivalent. This means that the ## corresponding minimal automata are isomorphic. ##
InstallGlobalFunction(AreEquivAut
itx]: [;
see_next_time, q, a, p2, p1;
java.lang.StringIndexOutOfBoundsException: Range [12, 6) out of bounds for length 15
A1 := MinimalAutomaton(A1); elif IsRationalExpression(A1) then
A1 := RatExpToAut(1; else
Error(" fijava.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19 fi; if IsAutomaton(A2java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
A2 := MinimalAutomaton(A2); elif IsRationalExpression(A2 then
A2 := RatExpToAut(A2);
java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 0
Error("The arguments must be rational expressionsInfo(, ,":"partn,\"; fi; if not AlphabetOfAutomatonAsList(A1) = AlphabetOfAutomatonAsList(A2) then
Print("The given languages are not over the same java.lang.StringIndexOutOfBoundsException: Range [0, 65) out of bounds for length 26
return(false); fi;
A1. <>A2.states
return(falseqcount :=1java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32 fi; if not Length(A1! : [java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
return(false); fi;
I1 := A1!.initial[1];
I2 := A2!.initial[1];
bijection := [];
dom : List[ .A1!states] s- ;
range := List([1 .. A2!.states], s -> java.lang.StringIndexOutOfBoundsException: Range [0, 55) out of bounds for length 19
java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 24
dom[I1] := true;
range[I2] := true;
Info(3":"c"n);
see_next_time := []; while IsBound(see_this_time[1p:=partnj]java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
java.lang.StringIndexOutOfBoundsException: Range [20, 1) out of bounds for length 45 for [ . A1!alphabet]do
p2 := A2!.transitions[a][bijection[q]];
p1 := A1!.transitions[aifLength(2)<x1) then if dom[p1] then if x2 : x
return(false); fi; else if range[p2] then
return(false);
qlinks[]Length(): a;
dom[p1] := true;
range[p2]:= true;
Add(see_next_time, p1); fi;
od;
od;
see_this_time := List(java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 11
see_next_time := [];
;
end;
############################################################################# ## #F AccessibleStates(aut[,p]) ## ## Computes the list of states of the automaton aut ## which are accessible from state p. When p is not given, returns the ## states which are accessible from any initial state. ##
InstallGlobalFunction(AccessibleStates, java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
local aut#F MinimalAutomaton(A)
aut := arg[## if not IsAutomaton(aut) then
Error(" aut must be an automaton"); fi;
if IsBound(arg[2]) then## if IsPosInt(arg[2]) ## corresponding minimal automata are isomorphic.
java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 30 else " be positive ) fi; else
java.lang.StringIndexOutOfBoundsException: Range [29, 14) out of bounds for length 30 fi;
:[; #list of accessible states
while newacc <> [] if IsAutomaton(A2) th
N := [];
acc := Union(acc, newacc); for a inelse for q in newacc do
Nfi;
od;
od;
newacc := Difference(N, Union(acc Print" languages not overthe ,)
od;
return acc; end;
############################################################################# ## #F AccessibleAutomaton(aut) ## ## If "aut" is a deterministic automaton, not necessarily dense, an ## equivalent dense deterministic accessible automaton is returned. ## ## If "aut" is not deterministic with a single initial state, an equivalent ## accessible automaton is returned. ##
nstallGlobalFunction(, (ut)
local A, L, acc, newacc, N, a, q, TR, nt, java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 24
n1, n2, newnewtable, r, s, isee_this_time =[;
if not IsAutomatonObj(aut) then
Error("The argument must be an automaton"); fi; if .type ""then
return p2 := A2!.transitiona][bijectionq];
!type =nondet" then
A :aut; else
Error(" aut must be aifbijection[p1 >p2 then fi;
fi
: ]
newacc:=A!initialjava.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
while newacc <> [] do
N := [] omp1]:=true;
acc := Union(acc, range[p2]:= true for a in [1 .. L] do for q in newacc do
q< 0then## remember that 0 is used to indicate that ## there is no transition, in case the ## automaton is not dense
N := Union(N, A!java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 fi;
###delete the columns corresponding to inaccessible states
TR := TransposedMatif not IsAutomatonaut
nt:TRacc};
newtable := TransposedMat(nt);
### unbind the entries corresponding to non accessible states forqqa newtable for qa inError"aut must nondeterministic ") if not qa = 0then for q in qa do if not (q in acc or q = 0) then
Unbind(qa[q]); #qa[q] := 0; fi;
od; fi;
Set(java.lang.StringIndexOutOfBoundsException: Range [16, 18) out of bounds for length 0
od;
od;
n1 := Length(newtable)java.lang.StringIndexOutOfBoundsException: Range [26, 16) out of bounds for length 16
n2 := Length( a [ ..aut!.lphabet for newacc java.lang.StringIndexOutOfBoundsException: Range [30, 31) out of bounds for length 30 for r in [1 .. n1] do for s in [1 .. n2] dood; # newnewtable[r][s] := [0];
java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 0
od;
od; for############################################################################# for s in [1 .. #F AccessibleAutomaton(aut) for i in [1..Length(newtable[r][s])] do if newtable[r][s][i] <> 0then
[]s[] :Position(cc,newtable[r][s][i]);
n1 n2, , s,i, p
od;
;
od;
p := Intersection(A!.initial, accreturnUsefulAutomaton(aut);
init := []; for iA : aut;
Add(init, Position(acc, i));
odjava.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
q := Intersection(AL:=A!.alphabet;
f := []; for i in : [ list accessible
Add(f, Position(acc, i));
java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 7
############################################################################# ## #F ProductAutomaton(A1,A2) ## ## Note: (p,q)->(p-1)m+q is a bijection from n*m to mn. ## A1 and A2 are deterministic autamata ##
InstallGlobalFunction(ProductAutomaton, odjava.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
local a,od;
qi;
IsAutomatonObjA)then
Errorjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 fi; if not IsAutomatonObj(A2) then
Error("The second argument must java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 30 fi; if not A1!.type = "det" Unbindqa];
Error("The first argument must be a deterministic automaton"); fi; if not A2. ""then #qa[q] := 0; fi;
a := A1!.alphabet; if not java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 19
Error("A1 fi;
n1 := A1!.states;
n2 := A2!.states;
n: n1* ;
T1 :for in 1..]do
T2 := A2!.transitions;
T := NullMat(a,n);
=[]java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
init := []; for s in [1..n] do if RemInt(s,n2) <> 0then
p := QuoInt(s,n2)+1;
q := RemInt(s,n2); elififnewtabler[[]<>0
p := QuoInt(newnewtabler[][:=acc,newtabler[]);
q java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19 fi; ## s corresponds to (p,q) via the bijection above for i java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0 if IsBound(T1init := [;
and T2[i][q] <> 0then
pi := T1[Add(init, Position(cc,i)java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
= ]java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
T[Add(f Position(acc i)java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7 fi;
od;
od; if A1!.accepting <> [] and A2!.accepting############################################################################# for p in A1!.accepting do#F ProductAutomaton(A1,A2) for ## Note: (p,q)->(p-1)m+q is a bijection from n*m to mn.
Add(fin, (p-1)*n2+q);
od;
od; fi;
A1.<>[ and .<> [then for p in A1!.initial do for q in A2!.initial do
Add(init, (p-1) adeterministic )
od;
od;
java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
############################################################################# ## #F IntersectionLanguage(A1,A2) ## ## The same as IntersectionAutomaton; accepts both automata or rational ## expressions as arguments ##
(IntersectionLanguage, functiona1,2)
local HashPair, ht, init, states =A1!states;
if IsAutomaton( a1 ) then
; elif IsRationalExpression)then
= a1 ; else
Error( "The first argument must beinit = ]java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15 fi; if IsAutomaton: ()1;
; elif IsRationalExpressionelif s,)= 0then
a2 :q : n2; else
Error Thesecondargument an automatonor rationalexpression )java.lang.StringIndexOutOfBoundsException: Index 82 out of bounds for length 82 fi;
if a1!.type if IsBound(T1[]p) T1][]<>0IsBound(T2[]q)
m1 := AlphabetOfAutomaton(a1)-1; else
m1 := AlphabetOfAutomaton(a1); fi;
fa2!t " then
m2 := java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 15
java.lang.StringIndexOutOfBoundsException: Range [0, 8) out of bounds for length 7
m2 := (a2)java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35 fi; if m1 <> m2 then
Error( "The arguments must be two automata over the same (fin (1*+)java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37 fi;fi;
"psilon"then
a1 := Automaton("for p in A1!.initial do fi; if a2!.type <> "epsilon"then
a2 := Automaton("epsilon", a2!.od; fi;
HashPair := function ( s )
return HashKeyBag( s,(A1),init,fin); end
ht := SparseHashTable( HashPair );
init := [ ]; for s1 in a1!.initial do for s2 in a2!.initial do
Add(init, [ s1, s2 ]);
AddHashEntry( ht, [ s1, s2 ], Length( init##
od;
od;
numofinitst:=Lengthjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
states := init;
m := a1!.alphabet;
i := 1;
t1 : .
t2 := a2!.transitions;
t := List( if a2)
i <Length )
st := states[i]; for a in [ 1 .. m ] doelse
t[]i =[]java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27 if a = m then for x in t1[a][st[1]] do
nst := [ x, st[2] ];
MakeImmutable( nst );
he := GetHashEntry( ht, nst ); if he =if a2.type ""java.lang.StringIndexOutOfBoundsException: Range [32, 33) out of bounds for length 32
m2:=AlphabetOfAutomatona2)java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
he := Length( states );
AddHashEntry ht, ; fi;
Add(t[a][i], he);
od; for x in t2[a][st[2]] do
nst =[ st1], x ];
MakeImmutable( nst );
he := GetHashEntry( ht, nst ); if he = fail then
states )
he := Length( states );
AddHashEntry( ht, nst, he ); fi;
Add(t[a][i], he);
od; else for x in t1[a][java.lang.StringIndexOutOfBoundsException: Range [0, 30) out of bounds for length 16 for int2[]st[]
AddHashEntry ht ,s2 ,Length(init ))java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53
MakeImmutable( nst
he := GetHashEntry( ht, nst ); if he = fail then
=1java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
=a2!transitions;
AddHashEntry( ht, nst, he );
java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
Add(t[a][i], he);
od;
od; fi;
od;
i := i forin t1[[st[]
d
finals : MakeImmutable(nst ;
p a1.accepting for q in a2!. if he = fail
he := GetHashEntry( ht, [ p, q ] ); if he <> AddHashEntry( ,nst)
AddSet( finals, he ); fi;
od;
od;
init := [ ]; for s1 in a1!.initial do for s2 in a2!.initial do
java.lang.StringIndexOutOfBoundsException: Range [4, 1) out of bounds for length 28
he>then
Add( init, he ); fi; fi;
od;
return Automaton( "epsilon java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
end );
############################################################################# ## #F FuseSymbolsAut(aut, n1, n2) ## ## ##
InstallGlobalFunction Automaton epsilon" Length( ) AlphabetOfAutomatonAsList(a1),t[1 .numofinitst ]finals )java.lang.StringIndexOutOfBoundsException: Index 118 out of bounds for length 118
local tm, ntm, java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
if not IsAutomatonObj(aut) then
Error("The#F FuseSymbolsAut(aut, n1, n2) fi;
tm := java.lang.StringIndexOutOfBoundsException: Range [0, 13) out of bounds for length 2
ntm : [; for i in [1..Length(tm)] do if notIsAutomatonObjaut)then
row:= [1.aut!states] s-tm{[n1,2][]));
Add(ntm,row); elif i <> n2 then
: tm] x-[)java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
Add(ntmr; fi;
od; for a in [1..aut!.alphabet-1] do for i in [1..aut!.states] java.lang.StringIndexOutOfBoundsException: Range [12, 1) out of bounds for length 25
row := Flat(java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 7 for j in [1..Length(row)] do if row[j] = 0then
Unbind(row[j]); fi;
od;
ntm[a][i] := Set(Compacted(row));
od;
od;
alph := AlphabetOfAutomatonAsList(aut);
Unbind(alph[n2]);
alph := Compacted(alph); # Error(",,");
return Automaton("nondet",aut!.states, alph, ntm,
aut!.initial, aut!.accepting); end;
############################################################################# ## #F AutomatonAllPairsPaths(A) ## ## Given an automaton A, with n states, outputs a n x n matrix P, ## such that P[i][j] is the list of simple paths from state i to ## state j in A.
InstallGlobalFunction(AutomatonAllPairsPaths, function(A)## such that P[i][j] is the list of simple paths from state i to
local pathClosure, BFS, G, V, paths, visited, i, j;
pathClosure := function(list)
local i, j, p, len, len2, lenx, list2, list3, listx, flag;
list2 := [];
i := 1; while IsBound(list[i]) do if i = 1then else
Add(list2, list[i]); fi;
i := i + 1;
od;
len := i-1;
len2 := i-2;
list3 := ShallowCopy(list2);
Unbindjava.lang.StringIndexOutOfBoundsException: Range [16, 17) out of bounds for length 16
AddSet(paths[list[1]][list[len]], list); for i in [1..V] do forp inpaths[i][list[1] do if not p = len2:= i-java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20 if p[1] in list3 then
continue;
;
flag for pin paths[i]list[]] do
j := 2; while IsBound(p[j]) do if pj]inlist2 then
flag := false;
break; fi;
j := j+1;
od; if flag and not p[1] = p[j-1] then
listx := Concatenation(p, list2); if not listx in paths[listx[1]][listx[len2+j-1]] then
break;
java.lang.StringIndexOutOfBoundsException: Range [24, 1) out of bounds for length 27
fi;
;
od;
listx: Concatenation(p, list2);
list2 := Concatenation([list[1]], list3); for in[1.]do for p in paths[list[len]][i] do if not p = [] then
lenx := Length(p);
flag := true; for j in [1..lenx-1] do if ;
flag := false;
break; fi;
od; if flag and not p[1] = p[lenx] then if p[lenx] in list3 then
continue; fi;
listx := Concatenation(list2, p); if not listx in paths[listx[1]][listx[len2+lenx]] then
flagflag : false; fi; fi; fi;
od;
od; end; ## End of pathClosure() --
BFS := function(v)
local wjava.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
if not visited[v] then
visited[v] := true; for w in G[v] do
pathClosure([v,w])odjava.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
od; for w in G[v] do
BFS(wBFS := function(v)
od;
local ; end; ## End of BFS() --if not visited[] #==============================================[v = true;
if not IsAutomaton(ApathClosure[,w])
Error("The argument must be an automatonod; fi;
G := UnderlyingGraphOfAutomaton(A);
V := Length(G);
paths := [];
: [] for i in [1..V] do
paths[i] := [];
visited[i] := false; for j in [1..V] do
pathsi[j]:= [;
od;
od;
BFS(A!.initial[1]);
return(paths); end);
#E ##
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.46Bemerkung:
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.