-
Notifications
You must be signed in to change notification settings - Fork 0
Operations On Automata
###Concatenation
Concatenating two automata will create a new automaton that will accept the concatenation of their languages.
(a) + (b) //or
(a) concatenate (b) //accepts the string "ab"
We can also concatenate a list of automata:
(a) concatenate List((b), (c), (d)) //or
(a) ++ List((b), (c), (d)) //accepts the string "abcd"
###Union
Getting the union of two automata will create a new automaton that will accept the union of their languages.
(a) | (b) //or
(a) union (b) //accepts the strings "a" and "b"
We can also get the union of a list of automata:
(a) union List((b), (c)) //accepts the strings "a", "b", and "c"
###Complement
The normal complement methods will get the complement of a DFA relative to its alphabet.
For example if we get the complement of an automaton that represents "a+" (one or more a's) then the returned automaton will only accept the empty string.
!(a+) //or
(a+).complement
There are two additional methods for getting the complement of an automaton. We can get the complement relative to either another automaton or an alphabet.
For example if we get the complement of an automaton that represents "a*" (zero or more a's) relative to the automaton "b*" then the returned automaton will be "b+". Getting the complement of "a*" relative to the alphabet [a,b] would return an automaton that accepts any string in the language that contains at least one 'b'.
(a*).relativeComplement(b*) //complement relative to another automaton
(a*).relativeComplement(Set('a','b')) //complement relative to an alphabet
###Intersection
The intersection of two automata will return a new automaton that accepts strings that are accepted by both of the provided automata.
(a*) & (b*) //or
(a*) intersect (b*) //accepts only the empty string
###Subtraction
The subtraction of two automata will return a new automaton that accepts strings that are accepted by the first automaton minus strings that are accepted by the second automaton.
(a*) minus (b*) //or
(a*) - (b*) // accepts (a+)
###Reversal
The reversal of an automaton will accept the reversal of the provided automaton's language.
(a+b).reverse //accepts (b+a)
###Repetitions
There are several methods for getting repetitions of an automaton. These methods will return an automaton that will accept the repetition of the given automaton's language a certain amount of times.
(a)* //or
(a).repeat //accepts zero or more a's
(a)+ //accepts one or more a's
(a).optional //or
(a)? //accepts zero or one a
(a).repeat(x) //accepts x or more a's
(a).repeat(x,y) //accepts a minimum of x and a maximum of y a's
###Substitutions
We can substitute a character in an automaton's language with another character, string, or automaton:
(a*).substitute('a','b') //returns b*
(a*).substitute('a',"foo") //returns (foo)*
(a*).substitute('a', (b+a+r)) //returns (bar)*