GAP (kbmag) - Chapter 4: The stand-alone package

Goto Chapter: Top 1 2 3 4 Bib Ind
[Top of Book] [Contents] [Previous Chapter] [Next Chapter]

[MathJax on]

4 The stand-alone package
4.1 Functions for manipulating finite state automata
4.1-1 IsInitializedFSA
4.1-2 InitializeFSA
4.1-3 FSA
4.1-4 WriteFSA
4.1-5 IsDeterministicFSA
4.1-6 AlphabetFSA
4.1-7 NumberOfStatesFSA
4.1-8 NumberOfLettersFSA
4.1-9 AcceptingStatesFSA
4.1-10 InitialStatesFSA
4.1-11 DenseDTableFSA
4.1-12 SparseTableFSA
4.1-13 TargetDFA
4.1-14 TargetsFSA
4.1-15 SourcesFSA
4.1-16 WordTargetDFA
4.1-17 IsAcceptedWordDFA
4.1-18 AddStateFSA
4.1-19 DeleteStateFSA
4.1-20 PermuteStatesFSA
4.1-21 AddLetterFSA
4.1-22 DeleteLetterFSA
4.1-23 PermuteLettersFSA
4.1-24 AddEdgeFSA
4.1-25 DeleteEdgeFSA
4.1-26 SetAcceptingFSA
4.1-27 SetInitialFSA
4.1-28 IsAccessibleFSA
4.1-29 AccessibleFSA
4.1-30 IsTrimFSA
4.1-31 TrimFSA
4.1-32 IsBFSFSA
4.1-33 BFSFSA
4.1-34 LSizeDFA
4.1-35 LEnumerateDFA
4.2 Functions calling external programs
4.2-1 DeterminizeFSA
4.2-2 MinimizeFSA
4.2-3 NotFSA
4.2-4 StarFSA
4.2-5 ReverseFSA
4.2-6 ExistsFSA
4.2-7 SwapCoordsFSA
4.2-8 AndFSA
4.2-9 OrFSA
4.2-10 ConcatFSA
4.2-11 LanguagesEqualFSA
4.2-12 GrowthFSA

### 4 The stand-alone package

The KBMag package contains GAP interfaces to many of the functions for manipulating finite state automata (fsa) that are available in the stand-alone. We shall list these here, without giving much detail. For more detail, the user could try looking in the source file `gap/fsa4.g`.

#### 4.1 Functions for manipulating finite state automata

fsa are currently implemented as GAP records, as they were previously in GAP3. This interface may be updated to the style of GAP4 at some stage. (Note that the abbreviation fsa will be used for both singular and the plural.)

The alphabet of an fsa is itself a record that must contain at least the two components `type` and `size`, where `type` is a string, and `size` a positive integer. The easiest possibility is to use the type `simple`, and then no other record components are necessary. There are several more complicated possibilities, which are used by the other rewriting system functions. For example, there is the type `identifiers`, for which fields `format` and `names` are necessary. For example:

    gap> M := FreeMonoid( 3 );;
    gap> alph := rec( type := "identifiers", size := 3,
    >                 format := "dense", names := [M.1,M.2,M.3] );;

defines a valid alphabet for an fsa. The members of the alphabet are referred to as `letters`, and can be represented either by a positive integer or by their name (usually a generator of a free group or monoid) if they have one.

The functions `ReductionAutomaton` (2.5-2), `WordAcceptor` (2.6-2), `FirstWordDifferenceAutomaton` (2.6-2), `SecondWordDifferenceAutomaton` (2.6-2) and `GeneralMultiplier` (2.6-2) mentioned in earlier sections all return a fsa. The other possibilities for the user to construct a fsa are to use the function `FSA` (4.1-3) or to read one in from a file. In the latter case, the user must immediately call `InitializeFSA` (4.1-2) on the record that has been read in. For example, running GAP from the package directory:

    gap> Read( "standalone/fsa_data/fsa_2" );
    gap> InitializeFSA( fsa_2 );

##### 4.1-1 IsInitializedFSA

`‣ IsInitializedFSA`( fsa ) | ( function )

Tests whether fsa is a record describing a valid initialized fsa.

##### 4.1-2 InitializeFSA

`‣ InitializeFSA`( fsa ) | ( function )

Initializes a record representing a fsa that has been read in from a file.

##### 4.1-3 FSA

`‣ FSA`( alph ) | ( function )

Returns an initialized fsa with alphabet `alph` having one state that is an initial and final state, and no transitions (edges).

The arguments of the following functions must be initialized fsa.

##### 4.1-4 WriteFSA

`‣ WriteFSA`( fsa ) | ( function )

Displays fsa nicely. (In a proper implementation, this would be the `ViewObj` function.)

##### 4.1-5 IsDeterministicFSA

`‣ IsDeterministicFSA`( fsa ) | ( function )

Tests whether fsa is a deterministic fsa. Many of the functions below work only for deterministic fsa. A deterministic fsa with the same language as fsa can be constructed with the function `DeterminizeFSA` (4.2-1).

##### 4.1-6 AlphabetFSA

`‣ AlphabetFSA`( fsa ) | ( function )

`‣ StatesFSA`( fsa ) | ( function )

Return, respectively, the records representing the alphabet and state-set of fsa.

##### 4.1-7 NumberOfStatesFSA

`‣ NumberOfStatesFSA`( fsa ) | ( function )

Returns the number of states of fsa.

##### 4.1-8 NumberOfLettersFSA

`‣ NumberOfLettersFSA`( fsa ) | ( function )

`‣ SizeOfAlphabetFSA`( fsa ) | ( function )

Returns the size of the alphabet of fsa.

##### 4.1-9 AcceptingStatesFSA

`‣ AcceptingStatesFSA`( fsa ) | ( function )

Returns the list of accepting states of fsa.

##### 4.1-10 InitialStatesFSA

`‣ InitialStatesFSA`( fsa ) | ( function )

Returns the list of initial states of fsa.

##### 4.1-11 DenseDTableFSA

`‣ DenseDTableFSA`( fsa ) | ( function )

fsa must be deterministic. The transition table is returned as a list of lists, where the e-th entry in the s-th inner list is `TargetDFA` (4.1-13), called as `TargetDFA(fsa,e,s);`.

##### 4.1-12 SparseTableFSA

`‣ SparseTableFSA`( fsa ) | ( function )

The transition table is returned as a list of lists, where each entry in the s-th inner list is is a two-element list `[e,t]` of integers that represents a transition from state number s to state number t under letter number e. We can also have e=0, representing transitions with no label (ϵ transitions).

##### 4.1-13 TargetDFA

`‣ TargetDFA`( fsa, e, s ) | ( function )

fsa must be a deterministic fsa, e should be a number or name of a letter of the alphabet, and s a number of a state of fsa. The target of s under e is returned, or 0 if there is no target.

##### 4.1-14 TargetsFSA

`‣ TargetsFSA`( fsa, e, s ) | ( function )

Similar to `TargetDFA` (4.1-13), but fsa need not be deterministic, and a list of targets is returned.

##### 4.1-15 SourcesFSA

`‣ SourcesFSA`( fsa, e, s ) | ( function )

Similar to `TargetsFSA` (4.1-14), but the list of sources of transitions to s under e is returned. Note that e can also be zero here.

##### 4.1-16 WordTargetDFA

`‣ WordTargetDFA`( fsa, w ) | ( function )

fsa must be a deterministic fsa, and w should be a list of integers or a word in the alphabet (in the case when the alphabet is defined from a free group or monoid). The target of the initial state of fsa under w is returned, or 0 if there is no such target.

##### 4.1-17 IsAcceptedWordDFA

`‣ IsAcceptedWordDFA`( fsa, w ) | ( function )

fsa must be a deterministic fsa, and w should be a list of integers or a word in the alphabet (in the case when the alphabet is defined from a free group or monoid). This function tests whether w is in the language of fsa.

##### 4.1-18 AddStateFSA

`‣ AddStateFSA`( fsa ) | ( function )

Adds an extra non-accepting state to fsa with no transitions to or from it.

##### 4.1-19 DeleteStateFSA

`‣ DeleteStateFSA`( fsa ) | ( function )

Deletes the highest numbered state together with all transitions to and from it from fsa. Use `PermuteStatesFSA` (4.1-20) first to delete a different state.

##### 4.1-20 PermuteStatesFSA

`‣ PermuteStatesFSA`( fsa, p ) | ( function )

p should be a permutation of [1..ns], where fsa has ns states. The states are permuted, where the original state number n becomes the new state number n^p.

##### 4.1-21 AddLetterFSA

`‣ AddLetterFSA`( fsa[, name] ) | ( function )

Adds an extra letter to the alphabet of fsa with no associated transitions. If the alphabet of fsa is defined over a free group or monoid, then `name` specifies the element of this free structure corresponding to the new letter.

##### 4.1-22 DeleteLetterFSA

`‣ DeleteLetterFSA`( fsa ) | ( function )

Deletes the highest numbered letter together with all associated transitions from the alphabet of fsa. Use `PermuteLettersFSA` (4.1-23) first to delete a different letter.

##### 4.1-23 PermuteLettersFSA

`‣ PermuteLettersFSA`( fsa, p ) | ( function )

p should be a permutation of [1..na], where the alphabet of fsa has na letters. The letters are permuted, where the original letter number n becomes the new letter number n^p.

##### 4.1-24 AddEdgeFSA

`‣ AddEdgeFSA`( fsa, e, s, t ) | ( function )

Adds an extra transition to fsa with source s, target t and letter e. If there is already such a transition, then this function does nothing.

##### 4.1-25 DeleteEdgeFSA

`‣ DeleteEdgeFSA`( fsa, e, s, t ) | ( function )

Deletes the transition from fsa with source s, target t and letter e, if there is one.

##### 4.1-26 SetAcceptingFSA

`‣ SetAcceptingFSA`( fsa, s, flag ) | ( function )

`flag` should be `true` or `false`, and state number s is made accepting or non-accepting, respectively.

##### 4.1-27 SetInitialFSA

`‣ SetInitialFSA`( fsa, s, flag ) | ( function )

`flag` should be `true` or `false`, and state number s is made initial or non-initial, respectively.

##### 4.1-28 IsAccessibleFSA

`‣ IsAccessibleFSA`( fsa ) | ( function )

Tests whether fsa is accessible; that is, whether all states can be reached from the initial states.

##### 4.1-29 AccessibleFSA

`‣ AccessibleFSA`( fsa ) | ( function )

Removes all inaccessible states from fsa thus rendering it accessible without altering its language.

##### 4.1-30 IsTrimFSA

`‣ IsTrimFSA`( fsa ) | ( function )

Tests whether fsa is trim; that is, whether all states can be reached from the initial states, and a final state can be reached from all states.

##### 4.1-31 TrimFSA

`‣ TrimFSA`( fsa ) | ( function )

Removes all inaccessible states from fsa and all states from which an accepting state cannot be reached, thus rendering it trim without altering its language.

##### 4.1-32 IsBFSFSA

`‣ IsBFSFSA`( fsa ) | ( function )

Tests whether fsa is in `bfs` (breadth-first-search) form; that is, whether the initial states come first and the other states appear in ascending order if one scans the transition table first by state number and then by alphabet number. Note that fsa must be accessible for it to be `bfs`.

##### 4.1-33 BFSFSA

`‣ BFSFSA`( fsa ) | ( function )

Replaces fsa by one with the same language but in `bfs` form. This can be useful for comparing the languages of two fsa. In fact `MinimizeFSA` (4.2-2) and `BFSFSA` are applied in turn to a deteministic fsa, then the resulting transition table is uniquely determined by the language of the fsa.

##### 4.1-34 LSizeDFA

`‣ LSizeDFA`( fsa ) | ( function )

The size of the acceted language of fsa, which must be deterministic. This only works if fsa is trim. If not, then `TrimFSA` (4.1-31) must be called first.

##### 4.1-35 LEnumerateDFA

`‣ LEnumerateDFA`( fsa, min, max ) | ( function )

The words in the language of fsa of length l satisfying min le l le max are returned in a list. The words will either be lists of integers, for simple type alphabets, of lists of words in the underlying free group or monoid for alphabets of type identifiers.

#### 4.2 Functions calling external programs

The remaining fsa functions all call external programs from the standalone. All of them except `DeterminizeFSA` (4.2-1) take only deterministic fsa as input, and all of them return deterministic fsa as output.

##### 4.2-1 DeterminizeFSA

`‣ DeterminizeFSA`( fsa ) | ( function )

Returns a deterministic fsa with the same language as fsa.

##### 4.2-2 MinimizeFSA

`‣ MinimizeFSA`( fsa ) | ( function )

Returns a fsa with the same language as fsa and a minimal number of states.

##### 4.2-3 NotFSA

`‣ NotFSA`( fsa ) | ( function )

Returns a fsa with the same alphabet as fsa whose language is the complement of that of fsa.

##### 4.2-4 StarFSA

`‣ StarFSA`( fsa ) | ( function )

Returns a fsa whose language is L^*, where L is the langauge of fsa.

##### 4.2-5 ReverseFSA

`‣ ReverseFSA`( fsa ) | ( function )

Returns a fsa whose language consists of the reversed words in the language of fsa.

##### 4.2-6 ExistsFSA

`‣ ExistsFSA`( fsa ) | ( function )

fsa should be two-variable fsa on an alphabet A. An fsa is returned that accepts a word w_1 ∈ A^* if and only if there exists a word w_2 ∈ A^* with (w_1,w_2) in the language of fsa.

##### 4.2-7 SwapCoordsFSA

`‣ SwapCoordsFSA`( fsa ) | ( function )

fsa should be two-variable fsa on an alphabet A. A two-variable fsa on A is returned that accepts (w_1,w_2) if and only if (w_2,w_1) is accepted by fsa.

##### 4.2-8 AndFSA

`‣ AndFSA`( fsa1, fsa2 ) | ( function )

fsa1 and fsa2 must have the same alphabet. The returned fsa has language equal to the intersection of those of fsa1 and fsa2.

##### 4.2-9 OrFSA

`‣ OrFSA`( fsa1, fsa2 ) | ( function )

fsa1 and fsa2 must have the same alphabet. The returned fsa has language equal to the union of those of fsa1 and fsa2.

##### 4.2-10 ConcatFSA

`‣ ConcatFSA`( fsa1, fsa2 ) | ( function )

fsa1 and fsa2 must have the same alphabet. The returned fsa accepts words of the form w_1w_2, where w_1 and w_2 are in the languages of fsa1 and fsa2, respectively.

##### 4.2-11 LanguagesEqualFSA

`‣ LanguagesEqualFSA`( fsa1, fsa2 ) | ( function )

fsa1 and fsa2 must have the same alphabet. This function tests whether the languages of fsa1 and fsa2 are equal, and returns `true` or `false`.

##### 4.2-12 GrowthFSA

`‣ GrowthFSA`( fsa ) | ( function )

Returns the growth function of fsa. This is a rational function, of which the the coefficient of x^n in its Taylor expansion is equal to the number of words of length n in the accepted language of fsa.

If the coefficients in this rational function are larger than about 16000 then strange error messages will appear and `fail` will be returned.

[Top of Book] [Contents] [Previous Chapter] [Next Chapter]
Goto Chapter: Top 1 2 3 4 Bib Ind

generated by GAPDoc2HTML