Chapter 3 REGULAR EXPRESSION
Chapter 3 REGULAR EXPRESSION
REGULAR EXPRESSION
Let
Σ be an alphabet. The class of “regular languages” over Σ is
a) ∅ is a regular language
c) For any natural number n ≥ 2, if L1, L2, L3, .... ,Ln are regular
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
Examples
0 + 1 represents the set {0, 1}
1 represents the set {1}
0 represents the set {0}
(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
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.
Similarly to describe ‘one or more ab’s”, that is {ab, abab,
ababab, .........}, you can use ab (ab)*.
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 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.
Example
Moore Machine
Moore machine is an FSM whose outputs depend on only the
present state.
A Moore machine can be described by a 6 tuple (Q, ∑, O, δ, X, q0)
Current State Input Next State Output
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
PROPERTIES OF REGULAR SETS (LANGUAGES)
Conclusion
A set is closed under an operation if, whenever the operation is
applied to members of the set, the result is also a member of
the set.
PROPERTIES OF REGULAR SETS (LANGUAGES)
There
are several operations defined on languages:
Theorem
Let L be a regular language. Then there exists a constant ‘c’ such that for every
string w in L −
|w| ≥ c
We can break w into three strings,
w = xyz, such that −
|y| > 0
|xy| ≤ c
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
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
Now we will swap its accepting states with its non-accepting states
and vice versa and will get the following −