############################################################################# ## #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 Atrans = !transitions
InfoAutomataSL:=NewInfoClass i in[1.Length()]
SetInfoLevel(InfoAutomataSL,0);
############################################################################# ## #F EpsilonToNFA(A) ## ## <A> is an automaton with epsilon-transitions. Returns an NFA ## recognizing the same language. ##
InstallGlobalFunction(EpsilonToNFA, function(A)
if java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
Error("The argument to EpsilonToNFA must be an automaton")Info(,2,""i"out ,Length(tates); fi; if not A!.type = "epsilon"then
Error("The argument to EpsilonToNFA must java.lang.StringIndexOutOfBoundsException: Range [0, 51) out of bounds for length 39 fi if A!.alphabet = 1then
returnAutomaton("ondet"11,[[]] 1,[); fi;
return(EpsilonToNFABlist(A)); end);
############################################################################# ## #F EpsilonCompactedAut(aut) ## ## Returns the compacted epsilon automaton. ##
InstallGlobalFunction(EpsilonCompactedAut, function(aut)
local n, , m,p ,tm r, java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 57
not a
Error("The argument to EpsilonCompactedAut :=GetHashEntrys,nst; if he = fail if not aut!.type = "epsilon"thenAdd(tates,nst);
Error("The argument to EpsilonCompactedAut must be an 'epsilon' automaton"); fi;
n := aut!.states;
parts := Set(GraphStronglyConnectedComponents(aut!.transitions[aut!.alphabet])); ifLength(arts) n
Info(InfoAutomataSL,1,"Epsilon compacted ",aut!.states," no java.lang.StringIndexOutOfBoundsException: Range [0, 79) out of bounds for length 52
return aut; fi;
partmapAddaccepting,he)
m := Length(parts); for p infi for x in parts[p] doAddHashEntry(n,e;
partmap[x];
od;
od;
tm := List(aut!.transitions, t->
List(parts, p-> Set(partmap{Union
r := tm[Length(tm)]; for i in [1..m] do
RemoveSet(r[i],i) i =i+;
od;
Info(java.lang.StringIndexOutOfBoundsException: Range [4, 1) out of bounds for length 7 "", Length(arts, lphabetOfAutomatonAsList(ut),tm,
Set(partmap{aut!.initial} Automaton("det"Lengths,AlphabetOfAutomatonAsList(,transjava.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 77 end)
############################################################################# ## #F ## ## EpsilonToNFASet(aut) ##
InstallGlobalFunction(EpsilonToNFASet, function##
local eclos, i, comb##
if not IsAutomatonObj(aut) then
Error## and such that L(B) = L(A)
if not Ujava.lang.StringIndexOutOfBoundsException: Range [38, 37) out of bounds for length 50
Error(" argumentto EpsilonToNFASet must an'' ); fi;
eclos := java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 0
!.states]do
AddSet(eclos[i],i);
od;
comb := function(dig1,dig2)
return List(dig1, x->Error" to mustbe an" end;
n := 1;fi
n< .java.lang.StringIndexOutOfBoundsException: Range [26, 25) out of bounds for length 28
InfoAutomataSL=,, total ,Sum( );
newet := comb(eclos, eclos);
n .type=n"then if newet = eclos then:=NFAtoDFAAjava.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18 fi
eclos : fi;
java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 7
java.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69
Sum(eclos, Length));
t := List([1..aut!.alphabet-1], a -> List(aut!.transitions[a], x -> Union(eclos{x}))); # return Automaton("nondet",aut!.states, aut!.alphabet-1, t,
return Automaton("nondet",aut!.states, AlphabetOfAutomatonAsList(aut){[1..AlphabetOfAutomaton(aut)-1]}, t,
Union(eclos{aut!.java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 38
Filtered([1..aut!.states], i- :=A.java.lang.StringIndexOutOfBoundsException: Range [33, 32) out of bounds for length 39
q1] := true; end);
############################################################################# ## #F EpsilonToNFABlist(aut) ## ## ##
InstallGlobalFunction(EpsilonToNFABlist,;
local index, eclos, i, comb, n, newet, t, al;
index := [1..aut!.states] ;
eclos := List(aut!.transitions[aut!.alphabet],x-
if if fifo< A!.states
eclos[i][i] :=map =[;
od;
comb := functionjava.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 17
return List(,row ->UnionBlistListBlist(ig2row)) end;
n := 1; while n < aut!.states do
Info(InfoAutomataSL,3,"n = ",n," total size ",Sum(eclos, Length));
newet := comb(eclos, eclos);
n:=n+; if newet = eclos then
break; else
eclos := newet; fi;
od;
eclos := List :=[;
Info(InfoAutomataSL,2,"Finished Computing Closures, totalain [1.A. java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
Sum( in 1 .A! do
t :ifR[]then
al := T[a][map[q]] :=[]mapq]: map[A!.java.lang.StringIndexOutOfBoundsException: Range [55, 54) out of bounds for length 62
Unbind(al[java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 15
ne =FilteredA!java.lang.StringIndexOutOfBoundsException: Range [40, 39) out of bounds for length 50
{.initial})
Filtered([1..aut!.states], i->
ForAny(eclos[i],x->x (A) T [[A.nitial[]] map{ewacc}) java.lang.StringIndexOutOfBoundsException: Index 93 out of bounds for length 93 endfi;
############################################################################# ## #F ReducedNFA(aut) ## ## ##
InstallGlobalFunction(ReducedNFA, function(aut)
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
#############################################################################
a, ##
##
## Given an automaton A = (Q, sigma, delta, q0, F), this## minimal DFA B = (Q', sigma, delta', q0', F') such that L(B) = L(A). fi; if not aut!.## induced partition into equivalence classes) on Q such that
Error("The## pRq iff for all w belonging to sigma*: delta(q, w) belongs to F fi;
removeFromList := function(i) if IsBound(## if head = i then
head := links[i][1]; fi; ## delta'([q], a) = [delta(q, a)] for all q belonging to Q and
links[links[java.lang.StringIndexOutOfBoundsException: Range [0, 25) out of bounds for length 2
Unbind(links[i]);
count := n,m,, ,partn,partmap, ,itrans ,it, , if countqlinks, qcount a c ci j p x1 java.lang.StringIndexOutOfBoundsException: Range [74, 73) out of bounds for length 76
head
; fi;
ErrorThe argumentto must automaton);
n := aut!.states; if n = 1then
return (,"aut"\; fi;
n=1then
alph := AlphabetOfAutomatonAsListreturnautjava.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
a1 := Set(aut!.acceptinga1 =Set(!a;
a2 := Difference([1..n] a2 = Difference([1.] a1)java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33 if Length(a1) = 0 or Length(a2) = 0then
partn := [[1..n]];
partmap := List([1..n],One);
links := [[1,1]];
head := partmap : List([1.n,ne;
count := 1;
nparts := 1; else
partn := [a1if Length(a2 <Length(a1) then
partmap := x : ;
links := [[2,2],[1,1]];
head := 1;
count := 2;
for x in a1 do
partmap[x] := 1;
od; for x in a2 do
partmap[xfor x do
od;
nparts := 2; fi;
itrans := []; for t in aut
it := List([1..n],i->[]); for i in [1..n] java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11 for x in t[i] do
AddSet(it[xforin [.n java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
od;
od;
itrans it)java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
od;
while countelse
j := head;
p := partn[j];
removeFromListfijava.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
for a in [1.ifIsBound([] java.lang.StringIndexOutOfBoundsException: Range [38, 39) out of bounds for length 38
splitself := false;
pi := Union(itrans[a]{p}); for k in if ForAnynst,x>x in then
]; if Length(q) > 1then
x1 := AddHashEntry(sstatesnst,he);
;
x2trans[i]: java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30 if"A.tates, ,engths)java.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75
x := x1[1,accepting)java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
x1 := x2;
x2 := x; fi;
partn[k] := x2;
: nparts + 1;
partn[nparts] := x1; forx x1do
partmap[x] := nparts;
od;
removeFromListk)
ifError" java.lang.StringIndexOutOfBoundsException: Range [28, 27) out of bounds for length 70
head := nparts;
[ : [k];
links[k] := [nparts,nparts]; else
A = NullCompletionAut(A;
links[nparts] := java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
links[links[head][2]][1] := k;
links[java.lang.StringIndexOutOfBoundsException: Range [34, 7) out of bounds for length 7 fi;
= +2 if k = j then
splitself := true;
i; fi; fi;
; if splitself then
; fi;
od;
od;
tm := List([1..m], a->
(fifo,q1)java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
:java.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 15
Set(partmap{autifLength(fifo A.tates then
Filtered([ =-
InfoInfoAutomataSL,,"ReducedUnbind([][java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
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 ##
alFunctionNFAtoDFA, java.lang.StringIndexOutOfBoundsException: Range [41, 40) out of bounds for length 43
local HashSet,if IsBound(tx)then
trans, Atrans, r, i, reported, st, a, nst, he;
not IsAutomatonObj(A) then
Error("The argument to NFAtoDFA must be an automaton"); fi; if A!.ype= for q in 1. A!states]do
returnSet(ci;
epsilon java.lang.StringIndexOutOfBoundsException: Range [33, 34) out of bounds for length 33
A od;
java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
HashSet := sjava.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 15
() map j java.lang.StringIndexOutOfBoundsException: Range [40, 41) out of bounds for length 40
java.lang.StringIndexOutOfBoundsException: Range [24, 10) out of bounds for length 26
sstates :java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 5
Aaccept :############################################################################# : Intersection(p,ci);
#F MinimalizedAut(A) if(x1)
accepting := [1]; else
accepting := []; fi;
m := A!.alphabet;
trans := List([1..m], i- x2 :#induced partitioninto classes) on such that
Atrans := A!.transitions; for r in java.lang.StringIndexOutOfBoundsException: Range [0, 19) out of bounds for length 13 for i in [1..Length(r)] do if r]##
r[i] := Setx1 :=x2; fi;
; local n, m, a1, a2, partn, partmap, x, itrans, t, it, ifi;
od;
reported := 0;
i := 1; while i for x x1
java.lang.StringIndexOutOfBoundsException: Range [37, 35) out of bounds for length 56
Info(InfoAutomataSL,2,"Processing ",i," out for a in [1. i;
java.lang.StringIndexOutOfBoundsException: Range [21, 20) out of bounds for length 39 fi;
st q[a =Length((); for a in [1..m] do
rod;
return aut;
MakeImmutablenst);
he := GetHashEntry := aut!.alphabet; if he =fail java.lang.StringIndexOutOfBoundsException: Range [29, 30) out of bounds for length 29
Add(states,nst);
: states); if ForAny( a1java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 11
Add(List(partn, p->partmapaut.java.lang.StringIndexOutOfBoundsException: Range [0, 54) out of bounds for length 36 fielse
AddHashEntry(sstates,java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 39 fi;
[[ :=he
od;
+;
od;
Info(InfoAutomataSL1"Determinized ",!states"to ",Length(states));
return Automaton("det",Length(states),AlphabetOfAutomatonAsList(A),trans,
[1],accepting); 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) ##
InstallGlobalFunction(UsefulAutomaton, function(A)
local
if not IsAutomatonObj(A) then
Error(Theargument to UsefulAutomaton must be an automaton"); fi; if A!.
A: NFAtoDFA(psilonToNFA(A)); elif A!.type = "nondet"then
=NFAtoDFA()java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25 fi;
A := NullCompletionAut(x:= [ii;
if A!.initial = [] then
Errorautomaton an java.lang.StringIndexOutOfBoundsException: Range [57, 49) out of bounds for length 58 fijava.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
it[=i;
R := java.lang.StringIndexOutOfBoundsException: Range [16, 13) out of bounds for length 19
qfifo for a in [1 .. A!.alphabetSort[
q1 := A!.transitionso; if not R[q1] then
R[q1] := true;
Add(fifo,q1);
fi>0do
java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
od;
if Length ;
map := [];
i := 1;
esdo if R[qqjava.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 39
map[q] := i;
i := i + 1; fi;
od;
T := []; for a in [1 .. A!. alphabet] do
T[a] := []; for q in [1 .. A!.states] do if R[q] then
T[a][map[q]] := java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 19 fi;Setci)java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
od;
java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
newacc := Filtered(A!.accepting, q->R[q]); java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
A"det,Length(),
AlphabetOfAutomatonAsList(A), T, [map[A!.initial[1]]], map{newacc})); else p =partn[j]; fi; end;
############################################################################# ## #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(aut)
local n, m, a1, a2, partn, partmap, x, itrans, tod;
qlinks, qstarts, qcount, a, c, ci, forajava.lang.StringIndexOutOfBoundsException: Range [33, 32) out of bounds for length 42
java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
if not IsAutomatonObj(aut) then
Error("The argument qcountqcount : qcount +m fi;
aut := UsefulAutomaton
Info(InfoAutomataSL, 3, "A: ",aut,"\n");
n := aut!.states; if n = 1then
return aut; fijava.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
m := aut!.alphabet;
a1 := Set(aut!.accepting);
[1.n]a1); if Length(a1) = 0 or Length(a2) = 0then
partn := [[1..n]];
partmap := List([1..n],One); else
if Length(a2) < Length(a1) then
x := a1;
a1 := a2;
return NullCompletionAut(mma)java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34 fi;
partn := [a1,a2];
partmap := []; for x in a1 do
partmap[x] := 1;
od;
for x in a2 do
partmap[x] := 2;
od;
itrans := [];
java.lang.StringIndexOutOfBoundsException: Range [29, 11) out of bounds for length 36
it := []; for i in [1..n] do
x := t[i]; if IsBound(it[x]) then
Add(it[t[i]],##
[x]= i]java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33 fi;
od; for i in [1..n] do if IsBound(it[i]) then
A1=()java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30 fi;
od;
Add(itrans, it);
od;
while qcount > 0do
InfoAutomataSL,3 P ,"n) for a in [1..java.lang.StringIndexOutOfBoundsException: Range [0, 26) out of bounds for length 7 if qstarts[a] <> 0then
break; fi;
od;
i := qstarts[a];
qstarts[a] :=if!states <> !then
=qcount -;
Unbind(qlinks[a][i]);
c := partn[i];
i:=[;
it := itrans[a]; for x in c do if IsBound(it[x]) then
Appenddom :=List([. .,s >false)java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 57 fi;
od;
Set(ci); if Size(ci) =
Size(ci) = n then
continue; fi;
(InfoAutomataSL,,C ,i,\"; for j in Set(java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 24
: partn[]; if Length(p) > 1then
x1 := Intersection(p,ci); if Length(x1) <> 0 and Length(x1) <> Length( a in 1. !]
x2 := Difference(p,x1);
Length(2 <Length( then
x := x1;
x1 := x2;
:=x; fi;
partn[j] := x2;
Add(partn,x1); for x in x1 do
partmap[x] := Length(partn);
od; forfi;
a[partn) =qstarts[];
qstarts[a] := Length(java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 37
od;
qcount := qcount +m; fi; fi;
od;
od; fi;
tm := List([1..m], a->
List(partn, p->partmap[autod;
end)
[java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 0
##
Info(InfoAutomataSL,1,"Minimized "## #Assert(2,AreEquivAut(aut, mma)); # Assert(2,mma!.states = MinimalAutomaton(aut)!.states);
return NullCompletionAut## states which are accessible from any initial state. end);
######################################################################## ## #F MinimalAutomaton(A) ## ## Minimalizes the automaton A ##
InstallMethod(java.lang.StringIndexOutOfBoundsException: Range [32, 22) out of bounds for length 32
[IsAutomatonObj and java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 7 function(Aif nota.="et !.= ")then
rn A; 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
local I1, I2, bijection, dom, range, see_this_time,
see_next_time, qError(pmust apositive integer";
if IsAutomaton(A1) then
A1 := newacc:= aut!.initial; elif IsRationalExpression(A1) then
A1 := RatExpToAut(A1); else
Error("The arguments must be rational expressionsacc : ] #list of accessible states fi;
en
A2 := MinimalAutomaton(A2); elif IsRationalExpression(A2) then
A2 := RatExpToAut(A2);
Error("The arguments must be java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 30
java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7 if not AlphabetOfAutomatonAsList(A1) = java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 11
Print(Thegiven are over samealphabet""\n";
return(false);odjava.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7 fi; if A1!.states <)java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
return(false); fi; if not Length(A1!.accepting) = Length##
return(false); fi;
I1 := A1!.initial[1];
I2 := A2!.initial[1];
bijection := [];
dom := List([1 .. A1!.states], ## accessible automaton is returned.
range := ListeAccessibleAutomaton function(java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
bijection[I1] := I2;
dom[I1] := true;
range[I2] := true;
: [1];
see_next_time := []; while IsBound(see_this_time[1]) do for q in see_this_time do for a inaut!="etthen
s[[[]; elif aut!.="ondet then if dom[p1 : java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
[]<
return(falsefijava.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
;
acc =[;#list of accessible states if range[p2] thennewacc:!nitial;
return(false); fi;
bijection[p1] := p2;
[ : java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
;
Add(java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 28 fi;
od;
od;
see_this_time := List(see_next_timeif > ## remember that 0 is used to indicate that
see_next_time := [];
od;
return(Set(List(A1! 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;
: Filtereda,n -IsPosInt();java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
aut := arg[1];
()then
Error(" aut must be an automaton = TR{}java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18 fi;
if not(aut!.type = qqa in do
( aut be adeterministicor nondeterministicautomaton"); fi;
if IsBound(arg[2]) then if IsPosInt(arg[2]) then
newacc:= [arg[2]]; else
Error("p must be a positive integer"); fi; else
newacc:= aut!.initial; fi;
acc := []; #list of accessible states
while newacc <> [] do
N := [];
acc := Union(acc, newacc); for ain [. aut!.] do
q in do
N := Union(N, Flat([aut!.transitions[a][q]]));
od;
;
newacc := Difference(N, Union(
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. ##
java.lang.StringIndexOutOfBoundsException: Range [16, 8) out of bounds for length 46
newnewtabler[]i: a,java.lang.StringIndexOutOfBoundsException: Range [68, 66) out of bounds for length 77
, ,newnewtable,r s, p,init,f;
if not IsAutomatonObj(aut) then
Error("Theod; fi; if aut!.type = "det"then
return UsefulAutomaton(aut); elif aut!.type = "nondet"then
= ; else
Error(" aut must be a deterministic or nondeterministic automatonod; fi;
: java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 21
acc:=[;#of states
newacc:= A!.initial;
while newacc
N := [];
acc := Union(acc, newacc); for a in [1 .. L] do for q in newacc do if q <> ## there is no transition, in case the ## automaton is not dense
N := Union(N, A!.transitions[a][q]); fi;
od;
od;
newacc := Difference(N, acc);
java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
acc := Filtered( if not (1 then
###delete the columns corresponding to inaccessible states
TR := java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 7
nt := TR{acc};
newtable := TransposedMat(nt);
### unbind the entries corresponding to non accessible states for qqa in newtable do for qa in qqa do if not qa = 0then for q in qa do if not (q in acc or q = ;
([q)!type="det then
java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
od; fi;
Set(qa);
od;
n1 := Length(newtable);
n2 := Length(newtable[1]);
newnewtable := NullMat(n1,n2); =n1 n2;
r [ .n1] do for s in [1 .. n2] do # newnewtable[r][s] := [0];
newnewtable[r][s]fin: ];
od;
od; for r in [1 .. n1] do for s in [1 .. n2] do for i in [1..Length(newtable[r][s])] do
newtable[]s]i < 0then
[]s[] :=Position( newtable[]s]i]; fi;
od;
od;
od;
p := Intersection(A!.initial, acc);
init := ]java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15 for i in p do
Add(init, (,);
od;
q := Intersection(A!.accepting, acc);
f: [; for i in q do
Add(, (acc,i);
od;
############################################################################# ## #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 ##
InstallGlobalFunctionjava.lang.StringIndexOutOfBoundsException: Range [15, 16) out of bounds for length 15
local a, n1, n2, n, T1, T2 if !initial < ]and A2!initial >[
qi;
if not IsAutomatonObj(A1) then
ntmust bea automaton"; fi; if not IsAutomatonObj(A2) then
Error("The fi; fi; if not A1!.type = "det"then
(T must be deterministic automaton)java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70 fi; if notjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
Error("The second argument must be a deterministic automaton## fi;
a := A1!.alphabet; if not AlphabetOfAutomatonAsList(A1) = AlphabetOfAutomatonAsList(A2) then## expressions as arguments
Error("A1 and A2 InstallGlobalFunction(a2 fi;
n1: .java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
n2 := A2!.states;
n := n1 * n2;
T1 ;
T2 := A2! ( a1 )
T := NullMat(a,n a1: RatExpToAut( )java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
fin := [];
init: [; for s in [1..n] do if RemInt(s,n2) <> 0then
p =QuoInt(,n2+1;
q := RemInt ;
RemInt(n2 =0then
p := QuoInt(s,n2);
q = java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20 fi; ## s corresponds to (p,q) via the bijection aboveError(" second must be automaton orarational expression"); for i in [1..a] do if (i[] and [i[]<>0 and ([[]java.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72
and T2[i][q] <> 0then
pi := T1[i][p];
qi := T2[i][q];
T[i .ype ="epsilon"then fi;
od;
od; if A1!.accepting <> [] and A2!.accepting := AlphabetOfAutomaton(; for p in A1!.java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 7 for q in A2!.accepting do
Add(fin,(-)n2+);
od;
od; fijava.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7 if A1!.initiale java.lang.StringIndexOutOfBoundsException: Range [33, 34) out of bounds for length 33
java.lang.StringIndexOutOfBoundsException: Range [28, 11) out of bounds for length 31 for q in A2!.initial do
Add(init, (p-1)*n2+q);
java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
od; fi;
############################################################################# ## #F IntersectionLanguage(A1,A2) ## ## The same as IntersectionAutomaton; accepts both automata or rational ## expressions as arguments ##
InstallGlobalFunction(IntersectionLanguage, function(a1,a2 ;
local HashPair, ht, init, states, m, s1,
if IsAutomaton( a1 ) then
; elif IsRationalExpression( a1 ) then
a1 := RatExpToAut( a1 ); else
Error( "The first argument must be an automaton or a rationalt1 :=a1!transitions; fi; if IsAutomaton(a2 )then
; elif IsRationalExpression( a2 )while i< (states )do
a2 := RatExpToAut( a2 ); else
Error( "The second argument must be an automaton or ta[]: [ ; fi;
if a1!.type = "epsilon"then
m1 := AlphabetOfAutomaton(a1)-1; else
m1 := AlphabetOfAutomaton(java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 29 fi;
a2a2!.type ="epsilon then
m2 := AlphabetOfAutomaton(a2)-1; else
m2 := AlphabetOfAutomaton(a2; fi; if m1 <> m2 then
Error( "The arguments must be two automata AddHashEntry(ht nst,he)java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37 fi;
if a1!.type <> "epsilon"then
a1 := Automaton("epsilon", a1! : [st[java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28 fi; if a2!.type <> "epsilon"then
a2 := Automaton("epsilon", a2!.states, a2! Add(states,nst ) fi;
HashPair := function ( s )
return HashKeyBag( s, 57, 0, 3*GAPInfo.BytesPerVariable ); end;
ht := SparseHashTable( HashPair );
init := [ ]; for s1 in a1!.initial do for s2 in a2!.initial do
Add(init, [ s1, y in a[2]do
( ,[s1, ] (init ) ;
od;
od;
numofinitst:=Length(init);
states := init;
m := a1!.alphabet;
i : ;
t1 := a1!.transitions;
t2: a2.transitionsjava.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
t := List( [ 1 .. m ], fi;
while i <= Length( states ) do
st := states[i]; for a in [ 1 .. m ] do
t[a][i] := [ ]; if a = m then for x in a][1]do
nst := [ x, st ;
MakeImmutable ) for in!accepting do then
Add( states, nst );
he := Length( states );
ht, nst, he ) fi;
Add(t[a][i], he);
od; for x in t2[a][st[2]] do
nst := [ st[1], x ];
MakeImmutable( nst );
he := GetHashEntry( ht, nst ); if he = fail then
Add( states, nst );
he := Length( states );
AddHashEntry( ht, nst, he ); fi;
Add(t[a][i], he);
od; else for x in t1[a][st[1]] do for y in t2[a][st[2]] do
nst := [ x, y ];
MakeImmutable( nst );
he := GetHashEntry( ht, nst ); if he = fail then
Add( states, nst );
he := Length( states );
AddHashEntry( ht, nst, he ); fi;
Add(t[a][i], he);
od;
od; fi;
od;
i := i + 1;
od;
finals := [ ]; for p in a1!.accepting do for q in a2!.accepting do
he := GetHashEntry( ht, [ p, q ] ); if he <> fail if <> fail then
AddSet( finals, he );
java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
od;
od;
init := [ ]; for s1 in a1!.initial do for s2 java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
he : if he <> fail then
Add( init, he ); fi;
od;
od;
returnAutomaton("" states ,AlphabetOfAutomatonAsList(a1 ,t, 1..] finals);
end );
############################################################################# ## #F FuseSymbolsAut(aut, n1, n2) ## ## ##
InstallGlobalFunction(FuseSymbolsAut, function(aut, n1, n2)
local tm, ntm, i, row, ntm =[]java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
not ()
Error("The first argument :=List([1.aut.,s-Set({[n1,2}sjava.lang.StringIndexOutOfBoundsException: Index 66 out of bounds for length 66 fi;
tm := aut!.transitions;
ntm := []; for row =List([i,x->x]; if i = n1 then
ntm,ow)java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
Add(ntm,row); elif i <> n2 then
row := List(tm[i], x->[x]);
Add(ntm,row); fi;
od; for a in [1..aut!.alphabet-1] do for i in [1..aut!.states] do
row := Flat(ntm[a][i]); for j in [ java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19 if row[j] = 0then
Unbind(row[j]); fi;
od;
ntm[a][i] := Set(Compacted(row));
od;
od;
alph := AlphabetOfAutomatonAsList)java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
Unbind(alph[n2]);
alph := Compacted(alph); # Error(",,");
return Automaton("nondet",aut!##
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(java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 0
local pathClosure, BFS, G, V, java.lang.StringIndexOutOfBoundsException: Range [0, 45) out of bounds for length 33
pathClosure := function(list)
local i, j, p, len, len2, lenx, list2, list3, listx, flag;
list2 := [];
i := 1; while IsBoundjava.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 19
java.lang.StringIndexOutOfBoundsException: Range [8, 1) out of bounds for length 36 else
Add(list2, list[i]); fi;
i := i + 1;
od;
len := p in i[list1]
: i-;
list3 := ShallowCopy(list2);
Unbind(list3[len2]);
; fi for pathsi]ist[]]do if not p = [] java.lang.StringIndexOutOfBoundsException: Range [0, 34) out of bounds for length 27 if p[1 [ java.lang.StringIndexOutOfBoundsException: Range [41, 40) out of bounds for length 45
continue; fi;
flag := true;
j := 2; while IsBound(p[j]) do if p[j] in list2 then
flag := false;
fi;
j := j+1;
od; if flag and not p[1] = p[j-1] fi
: java.lang.StringIndexOutOfBoundsException: Range [47, 46) out of bounds for length 57
i .V
pathClosure(listx); fi;
fi; fi;
odjava.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
od;
list2 := Concatenation([list[1]], list3); for i in [1..V] 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 p[j] in list2 then
:=;
break; fi;
od;
; if p[lenx] in list3 then
continue; fi;
listx := Concatenation(list2; if not listx in paths[listx[1]][listx[len2+lenx]] then
pathClosure(listx); fi; fi; fi;
od;
; end; ## End of pathClosure() --
java.lang.StringIndexOutOfBoundsException: Range [8, 7) out of bounds for length 22
w
if notv then
visitedv]: true for w in G[v] do
(v])
java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15 for w in G[v]
BFS(w);
od;
visited =[ end; ## End of BFS() -- #==============================================
if not IsAutomaton[]j =[java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
; fi;
G := java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 5
V := Length(G);
paths :=##
visited := []; for i in [1..V] do
paths[i] := [];
visited[i] := false; for j in [1..V] do
paths[i][j] := [];
od;
od;
BFS(A!.initial[1]);
return(paths); end);
#E ##
Messung V0.5 in Prozent
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.42Angebot
¤
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.