Automata What Is It?: Lar - Expressions - HTM
Automata What Is It?: Lar - Expressions - HTM
com/automata_theory/regu
lar_expressions.htm
Automata Theory Tutorial
PDF Version Quick Guide Resources Job Search Discussion
Automata Theory is a branch of computer science that deals with
designing abstract self-propelled computing devices that follow a
predetermined sequence of operations automatically. An automaton with a
finite number of states is called a Finite Automaton. This is a brief and
concise (краткий) tutorial that introduces the fundamental concepts of
Finite Automata, Regular Languages, and Pushdown Automata before
moving onto Turing machines and Decidability.
Audience
This tutorial has been prepared for students pursuing a degree in any
information technology or computer science related field. It attempts to help
students grasp the essential concepts involved in automata theory.
Prerequisites
This tutorial has a good balance between theory and mathematical rigor
(строгость). The readers are expected to have a basic understanding of
discrete mathematical structures.
Related Terminologies
Alphabet
Definition − An alphabet is any finite set of symbols.
Example − ∑ = {a, b, c, d} is an alphabet set where ‘a’, ‘b’, ‘c’, and ‘d’ are alphabets.
String
Definition − A string is a finite sequence of symbols taken from ∑.
Length of a String
Definition − It is the number of symbols present in a string. (Denoted by |S|).
Examples −
o If S=‘cabcad’, |S|= 6
Kleene Star
Definition − The set ∑* is the infinite set of all possible strings of all possible
Representation − ∑* = ∑0 ∪ ∑1 ∪ ∑2 ∪…….
Kleene Closure/Plus
Definition − The set ∑+ is the infinite set of all possible strings of all possible lengths over ∑ excluding λ.
Representation − ∑+ = ∑0 ∪ ∑1 ∪ ∑2 ∪…….
∑+ = ∑* − { λ }
Language
Definition − A language is a subset of ∑* for some alphabet ∑. It can be finite or infinite.
Example − If the language takes all possible strings of length 2 over ∑ = {a, b}, then L = { ab, bb, ba, bb}
q0 is the initial state from where any input is processed (q0 ∈ Q).
Example
Present State Next State for Input 0 Next State for Input 1
A a b
B c a
C b c
q0 is the initial state from where any input is processed (q0 ∈ Q).
Example
Q = {a, b, c}
∑ = {0, 1}
q0 = {a}
F={c}
The transition function δ as shown below −
Present State Next State for Input 0 Next State for Input 1
a a, b b
B c a, c
c b, c c
DFA vs NDFA
The following table lists the differences between DFA and NDFA.
DFA NDFA
Empty string transitions are not seen NDFA permits empty string
in DFA. transitions.
Classifier
A classifier has more than two final states and it gives a single output
when it terminates.
Transducer
An automaton that produces outputs based on current input and/or previous
state is called a transducer. Transducers can be of two types −
Mealy Machine − The output depends both on the current state and the current input.
δ*(q0, S) ∈ F
{S | S ∈ ∑* and δ*(q0, S) ∈ F}
δ*(q0, S′) ∉ F
{S | S ∈ ∑* and δ*(q0, S) ∉ F}
Example
Let us consider the DFA shown in Figure 1.3. From the DFA, the acceptable
strings can be derived.
Strings accepted by the above DFA − {0, 00, 11, 010, 101, ...........}
Strings not accepted by the above DFA − {1, 011, 111, ........}
Problem Statement
Let X = (Qx, ∑, δx, q0, Fx) be an NDFA which accepts the language L(X). We
have to design an equivalent DFA Y = (Qy, ∑, δy, q0, Fy) such that L(Y) =
L(X). The following procedure converts the NDFA to its equivalent DFA −
Algorithm
Input: NDFA
Output
equivalent DFA
:
Step 1 Create state table from given NDFA.
Create a blank state table under possible input alphabets for
Step 2
equivalent DFA.
Step 3 Mark start state of DFA by q0 (same as NDFA).
Step 4 Find out the combination of States {Q0, Q1,... , Qn} for each
possible input alphabet.
Step 5 Each time we generate a new DFA state under the input alphabet
columns, we have to apply step 4 again, otherwise go to step 6.
Step 6 States which contain any of final states of NDFA are final states of
equivalent DFA.
Example
The NDFA table is as follows −
q δ(q,0) δ(q,1)
a {a,b,c,d,e} {d,e}
b {c} {e}
c ∅ {b}
d {e} ∅
e ∅ ∅
Using above algorithm, we find its equivalent DFA. The state table of the DFA is shown in
below.
q δ(q,0) δ(q,1)
a {a,b,c,d,e} {d,e}
{d,e} e ∅
{b,d,e} {c,e} E
e ∅ ∅
d e ∅
{c,e} ∅ B
b c E
c ∅ B
Next Page
DFA Minimization
If there is an unmarked pair (Q i, Qj), mark it if the pair {δ(Qi, A), δ (Qi, A)} is marked for some input alphabet.
Step 4 Combine all the unmarked pair (Q i, Qj) and make them a single state in the reduced DFA.
Example
Let us use above algorithm to minimize the DFA shown below.
Step 1 − We draw a table for all pair of states.
a b c d e f
a b c d E f
c ✔ ✔
d ✔ ✔
e ✔ ✔
f ✔ ✔ ✔
Step 3 − We will try to mark the state pairs, with green colored check mark,
transitively. If we input 1 to state ‘a’ and ‘f’, it will go to state ‘c’ and ‘f’ respectively. (c, f) is
already marked, hence we will mark pair (a, f). Now, we input 1 to state ‘b’ and ‘f’; it will go to
state ‘d’ and ‘f’ respectively. (d, f) is already marked, hence we will mark pair (b, f).
a b c d E f
a
c ✔ ✔
d ✔ ✔
e ✔ ✔
f ✔ ✔ ✔ ✔ ✔
After step 3, we have got state combinations {a, b} {c, d} {c, e} {d, e}
that are unmarked.
So the final minimized DFA will contain three states {f}, {a, b} and {c, d, e}
Algorithm
Step 1 All the states Q are divided in two partitions − final states and non-final states and are denoted by P0. All the
states in a partition are 0th equivalent. Take a counter k and initialize it with 0.
Step 2 Increment k by 1. For each partition in Pk, divide the states in Pk into two partitions if they are k-distinguishable.
Two states within this partition X and Y are k-distinguishable if there is an input S such that δ(X, S) and δ(Y,
S) are (k-1)-distinguishable.
Step 3 If Pk ≠ Pk-1, repeat Step 2, otherwise go to Step 4.
Step 4 Combine kth equivalent sets and make them the new states of the reduced DFA.
Example
Let us consider the following DFA −
q δ(q,0) δ(q,1)
a b c
b a d
c e f
d e f
e e f
f f f
P0 = {(c,d,e), (a,b,f)}
P1 = {(c,d,e), (a,b),(f)}
P2 = {(c,d,e), (a,b),(f)}
Hence, P1 = P2.
There are three states in the reduced DFA. The reduced DFA is as follows −
Q δ(q,0) δ(q,1)
History[edit]
The Mealy machine is named after George H. Mealy, who presented the concept in a 1955 paper, “A Method for Synthesizing Sequential
Circuits”.[1]
Formal definition[edit]
A Mealy machine is a 6-tuple consisting of the following:
a transition function mapping pairs of a state and an input symbol to the corresponding next state.
an output function mapping pairs of a state and an input symbol to the corresponding output symbol.
In some formulations, the transition and output functions are coalesced into a single function .
Diagram[edit]
The state diagram for a Mealy machine associates an output value with each transition edge (in contrast to the state diagram for a Moore
machine, which associates an output value with each state).
When the input and output alphabet are both Σ, one can also associate to a Mealy Automata an Helix directed graph.[2] (S × Σ, (x, i) →
(T(x, i), G(x, i)))
This graph has as vertices the couples of state and letters, every nodes are of out-degree one, and the successor of (x, i) is the next
state of the automata and the letter that the automata output when it is instate x and it reads letter i. This graph is a union of disjoint cycles if
the automaton is bireversible.
Examples[edit]
Simple[edit]
State diagram for a simple Mealy machine with one input and one output.
A simple Mealy machine has one input and one output. Each transition edge is labeled with the value of the input (shown in red) and the
value of output (shown in blue).
The machine starts in state Si. (In this example, the output is the exclusive-or of the two most-recent input values;
thus, the machine implements an edge detector, outputting a one every time the input flips.
Complex
More complex Mealy machines can have multiple inputs as well as multiple outputs.
Applications[edit]
Mealy machines provide a rudimentary mathematical model for cipher machines. Considering the input and output alphabet the Latin
alphabet, for example, then a Mealy machine can be designed that given a string of letters (a sequence of inputs) can process it into a
ciphered string (a sequence of outputs). However, although one could use a Mealy model to describe the Enigma, the state diagram would
be too complex to provide feasible means of designing complex ciphering machines.
Moore/Mealy machines, are DFAs that have also output at any tick of the clock. Modern CPUs, computers, cell phones, digital clocks and
basic electronic devices/machines have some kind of finite state machine to control it.
Simple software systems, particularly ones that can be represented using regular expressions, can be modeled as Finite State Machines.
There are many of such simple systems, such as vending machines or basic electronics.
By finding the intersection of two Finite state machines, one can design in a very simple manner concurrent systems that exchange
messages for instance. For example, a traffic light is a system that consists of multiple subsystems, such as the different traffic lights, that
work concurrently.
number classification
watch with timer
vending machine
traffic light
bar code scanner
gas pumps
Summary[edit]
Implementing a Moore or Mealy machine is not that hard, especially if one does not intend to minimize the circuit.
However, it does take practice to be able to do it reasonably fast, and is difficult to understand conceptually, at least, at first. One should trace
out a few steps just to convince oneself of how it behaves. There is a subtle difference in the behavior of the implementation of a Mealy and
Moore machine. Tracing out a few steps can show the differences more clearly.
Usually, it is harder to understand why the circuit does the right thing (i.e., implements the FSM) than it is to know how to build it. Certainly,
one should devote time to both understanding why this technique works, as well as mastering the technique.
Introduction to Grammars
In the literary sense of the term, grammars denote syntactical rules for
conversation in natural languages. Linguistics have attempted to define
grammars since the inception of natural languages like English, Sanskrit,
Mandarin, etc. The theory of formal languages finds its applicability
extensively in the fields of Computer Science. Noam Chomsky gave a
mathematical model of grammar in 1956 which is effective for writing
computer languages.
Grammar
A grammar G can be formally written as a 4-tuple (N, T, S, P) where
Example
Grammar G1 −
Here,
S, A, and B are Non-terminal symbols;
Productions, P : S → AB, A → a, B → b
Example
Grammar G2 −
Here,
ε is an empty string.
x α y ⇒G x β y
Example
Let us consider the grammar −
Example
If there is a grammar
Here S produces AB, and we can replace A by a, and B by b. Here, the only
accepted string isab, i.e.,
L(G) = {ab}
Example
Suppose we have the following grammar −
Example
Problem − Suppose, L (G) = {am bn | m ≥ 0 and n > 0}. We have to find out
the grammarG which produces L(G).
Solution
Here, the start symbol has to take at least one ‘b’ preceded by any number
of ‘a’ including null.
To accept the string set {b, ab,bb, aab, abb, …….}, we have taken the
productions −
S → aS , S → B, B → b and B → bB
S → B → b (Accepted)
S → B → bB → bb (Accepted)
S → aS → aB → ab (Accepted)
Thus, we can prove every single string in L(G) is accepted by the language
generated by the production set.
Example
Problem − Suppose, L (G) = {a m bn | m> 0 and n ≥ 0}. We have to find out
the grammar G which produces L(G).
Solution −
Since L(G) = {am bn | m> 0 and n ≥ 0}, the set of strings accepted can be
rewritten as −
Here, the start symbol has to take at least one ‘a’ followed by any number
of ‘b’ including null.
To accept the string set {a, aa, ab, aaa, aab, abb, …….}, we have taken the
productions −
S → aA, A → aA , A → B, B → bB ,B → λ
S → aA → aB → a λ → a (Accepted)
Thus, we can prove every single string in L(G) is accepted by the language
generated by the production set.
Take a look at the following illustration. It shows the scope of each type of
grammar −
Type - 3 Grammar
Type-3 grammars generate regular languages. Type-3 grammars must
have a single non-terminal on the left-hand side and a right-hand side
consisting of a single terminal or single terminal followed by a single non-
terminal.
and a ∈ T (Terminal)
The rule S → ε is allowed if S does not appear on the right side of any rule.
Example
X → ε
X → a
X → aY
Type - 2 Grammar
Type-2 grammars generate context-free languages.
Example
S → X a
X → a
X → aX
X → abc
X → ε
Type - 1 Grammar
Type-1 grammars generate context-sensitive languages. The productions
must be in the form
αAβ→αγβ
where A ∈ N (Non-terminal)
The rule S → ε is allowed if S does not appear on the right side of any rule.
The languages generated by these grammars are recognized by a linear
bounded automaton.
Example
AB → AbBc
A → bcA
B → b
Type - 0 Grammar
Type-0 grammars generate recursively enumerable languages. The
productions have no restrictions. They are any phase structure grammar
including all formal grammars.
Example
S → ACaB
Bc → acB
CB → DB
aD → Db