0% found this document useful (0 votes)
33 views22 pages

Regular Expressions

The document provides an overview of regular expressions and their properties, including identity rules and methods for constructing regular expressions from finite automata. It includes exercises and examples demonstrating how to create regular expressions for specific languages and how to convert between regular expressions and automata. The document also outlines algorithms for building regular expressions from given DFAs and converting regular expressions to ε-NFAs.

Uploaded by

ratnakar babu M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views22 pages

Regular Expressions

The document provides an overview of regular expressions and their properties, including identity rules and methods for constructing regular expressions from finite automata. It includes exercises and examples demonstrating how to create regular expressions for specific languages and how to convert between regular expressions and automata. The document also outlines algorithms for building regular expressions from given DFAs and converting regular expressions to ε-NFAs.

Uploaded by

ratnakar babu M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

REGULAR EXPRESSIONS

M RATNAKAR BABU
Asst.Prof. CSE
Introduction
• The Language accepted by finite automata are easily described
by simple expressions called regular expressions.

• The regular expression is the most effective way to represent any


language.

• The language accepted by some regular expression is known

as a regular language.
Regular Expressions

1. Any terminal symbol(i.e. an element of ∑), Ꜫ and φ are regular


expressions.
2. The union of two regular expressions R1 and R2, written as R1+R2, is
also a regular expression.
3. The concatenation of two regular expressions R1 and R2, written as
R1R2, is also a regular expression.
4. The iteration(or Closure) of a regular expression R, written as R* is
also a regular expression.
5. If R is a regular expression , then (R) is also a regular expression.
Regular
Expressions
Identity Rules :
Let P,Q and R are the regular expressions then the identity rules are as follows:
1. φ +R = R
2. φR = Rφ = φ
3. ꜪR = RꜪ = R
4. Ꜫ* = Ꜫ and φ *= Ꜫ
5. R + R = R
6. R*R* = R*
7. RR* = R*R
8. (R*)*=R*
9. Ꜫ + RR*= R* = Ꜫ +R*R
10. (PQ)*P = P(QP)*
11. (P+Q)* = (P*Q*)* = (P* + Q*)
Regular
Expressions
• Exercise 2: Construct the regular expression for the language which accepts all the
strings which begin or end with either 00 or 11.
Solution:
The R.E. can be categorized into two subparts.
R = L1 + L2
L1 = The String which begin with 00 or 11.
L2 = The String which end with 00 or 11.
Let us find out L1 and L2.
L1 = (00+11)( any number of 0’s and 1’s )
L1 = (00+11)(0+1)*
L2 = ( any number of 0’s and 1’s ) (00+11)
L2 = (0+1)*(00+11)
Hence
R = [(00+11)(0+1)*] + [(0+1)*(00+11)]
Algorithm to build R.E. from given DFA

1. Let q1 be the initial state.


2. There are q2,q3,q4,….qn number of states. The final state may be
some qj where j<=n.
3. Let ji represents the transition from qj to qi.
4. Calculate qi such that
qi = ji .qj
If qi is a start state
qi = ji .qj +Ꜫ
5. Similarly compute the final state which ultimately gives the regular
expression r.
Regular
Expressions
• Exercise 1: Write a regular expression for the set of strings that
contains an even number of 1’s over ={0,1}. Treat zero 1’s as an
even number.
Solution:

0 0

Q0
1 Q1

The regular expression for the above F.A. is 0*10*1


DFA to RE via State Elimination (1)

1. Starting with intermediate states and then moving to accepting


states, apply the state elimination process to produce an equivalent
automaton with regular expression labels on the edges.
• The result will be a one or two state automaton with a start state and
accepting state.
DFA to RE State Elimination (2)

2. If the two states are different, we will have


an automaton that looks like the following:

R U

S
Start

We can describe this automaton as: (R+SU*T)*SU*


DFA to RE State Elimination (3)

3. If the start state is also an accepting state, then we must


also perform a state elimination from the original
automaton that gets rid of every state but the start state.
This leaves the following:
R

Start

We can describe this automaton as simply R*.


DFA to RE State Elimination (4)

4. If there are n accepting states, we must repeat the above steps for
each accepting states to get n different regular expressions, R1, R2,
… R n.
5. For each repeat we turn any other accepting state to non-
accepting.
6. The desired regular expression for the automaton is then the union
of each of the n regular expressions: R1 R2…  RN
DFARE Example

• Convert the following to a RE


0 0,1

1 1
Start 3 1 2

0
• First convert the edges to RE’s:
0 0+1

1 1
Start 3 1 2

0
DFA  RE Example (2)
0 0+1
• Eliminate State 1:
1 1
Start 3 1 2

• To: 0

0+10 0+1
Note edge from 33

11
Start 3 2

Answer: (0+10)*11(0+1)*
Second Example

• Automata that accepts even number of 1’s


0 0 0

1 1
Start 1 2 3

• Eliminate state 2: 1

0 0+10*1

10*1
Start 1 3
Second Example (2)
0 0+10*1

10*1
Start 1 3

• Two accepting states, turn off state 3 first


0 0+10*1

10*1
Start 1 3

This is just 0*; can ignore going to state 3 since we would “die”
Second Example (3)
0 0+10*1

10*1
Start 1 3

• Turn off state 1 second:

0 0+10*1

10*1 This is just 0*10*1(0+10*1)*


Start 1 3

Combine from previous slide to get


0* + 0*10*1(0+10*1)*
Converting a RE to an Automata

• We have shown we can convert an automata to a RE. To show


equivalence we must also go the other direction, convert a RE to
an automaton.
• We can do this easiest by converting a RE to an ε-NFA
RE to ε-NFA

• Basis:

a
R=a

ε
R=ε

R=Ø

Next slide: More complex RE’s


ε S ε
R=S+T

ε ε
T

ε
R=ST
S T

ε ε
R=S *
S

ε
RE to ε-NFA Example

• Convert R= (ab+a)* to an NFA


• We proceed in stages, starting from simple elements and working our way up

a
a

b
b

a ε b
ab
RE to ε-NFA Example (2)

ab+a a ε b
ε ε

a
ε ε

(ab+a)*
a ε b
ε ε
ε ε

a
ε ε

ε
End for Now
Continue in Next Class

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy