Professional Documents
Culture Documents
REGULAR EXPRESSION
Examples
0 + 1 represents the set {0, 1}
1 represents the set {1}
(0 +1)1 represents the set {01, 11}
(a+b)⋅(b+c) represents the set {ab, bb, ac, bc}
(0 + 1)* = ∈+ (0 + 1) + (0 + 1) (0 + 1) ..........= Σ*
(0 + 1 )+ =(0 +1) (0 +1)*= Σ+ =Σ*- {ε}
Building Regular Expressions
4
To say zero or more ab’s, i.e.,{λ, ab,abab........,} you need to say (ab)*.
One or more: Since a* means zero or more a’s, you can use aa*
(or equivalently a*a) to mean one or more a’s.
5
Hierarchy of evaluation of regular expression
6
Kleene Closure
Concatenation
Union
Regular Languages
7
ii. L = {a, ab} is a language over Σ = {a, b}because, both {a} and {b} are
iii. The language over the alphabet {0,1} where strings contain an even
Solution
s:
Regular Expressions to NFA
11
a (aa)+
FINITE AUTOMATA WITH OUTPUT
17
A finite-state
machine M = (Q , Σ, δ , λ, O , q0 ) consists of
a
finite set Q of states,
a
finite input alphabet Σ,
a
finite output alphabet O,
a
transition function δ that assigns to each state and input pair of a new
state,
an output function λ that assigns to each state and input pair an output, and
an
initial state q0.
There are two types of finite state machines that generate
output −
Mealy Machine
Moore Machine
Mealy Machine
A Mealy Machine is an FSM whose output depends on the
present state as well as the present input.
It can be described by a 6 tuple (Q, ∑, O, δ, X, q0)
M = (Q , O , ,Σ , δ , λ , q0 ) consists of
A finite set Q of states,
A finite input alphabet Σ,
A finite output alphabet O,
A transition function δ that assigns to each
state and input pair a new state,
An output function X that assigns to each
state and input pair an output, and
An initial state q0.
18
Examples
19
The above Mealy Machine outputs a value for each input. You can
tell input /output.
So for the following input:
000101010
It outputs
000010101
Moore Machine
20
A 0 D 0
A 1 B 0
B 0 E 0
B 1 C 0
C 0 F 0
C 1 C 0
D 0 G 0
D 1 E 0
E 0 H 0
E 1 F 0
F 0 I 1
F 1 F 0
G 0 G 0
G 1 H 0
H 0 H 0
H 1 I 1
I 0 I 1
I 1 I 1
Fig Example Moore machine
21
PROPERTIES OF REGULAR SETS (LANGUAGES)
22
There
are several operations defined on languages:
Select w such that |w| ≥ c
Select y such that |y| ≥ 1
Select x such that |xy| ≤ c
Assign the remaining string to z.
Select k such that the resulting string is not in L.
Hence L is not regular.
Problem
25
p ≠ 0, q ≠ 0, r ≠ 0. Thus |y|≠ 0
Let k = 2. Then xy2z = apa2qarbn.
Number of as = (p + 2q + r) = (p + q + r) + q = n + q
Hence, xy2z = an+q bn. Since q ≠ 0, xy2z is not of the form anbn.
Thus, xy2z is not in L. Hence L is not regular.
Complement of a DFA
26
Now we will swap its accepting states with its non-accepting states
and vice versa and will get the following −