Unit 2 TOC ODL
Unit 2 TOC ODL
Unit 2 TOC ODL
Unit No. 2
Theory of Computation
2 – Regular Expressions,
Regular Grammar And
Languages
Centre for Distance and Online Education
Objectives
After completing this session, you will be able to:
• The language accepted by finite automata can be easily described by simple expressions called
Regular Expressions.
• The languages accepted by some regular expression are referred to as Regular languages.
• A regular expression can also be described as a sequence of pattern that defines a string.
• String searching algorithm used this pattern to find the operations on a string.
4. Write the regular expression for the language accepting all the string
which are starting with 1 and ending with 0, over ∑ = {0, 1}.
Solution : R = 1 (0+1)* 0
5. Write the regular expression for the language accepting all the string
in which any number of a's is followed by any number of b's is
followed by any number of c's.
Solution: R = a* b* c*
6. Write the regular expression for the language over ∑ = {0} having
even length of the string.
• Solution: L = {ε, 00, 0000, 000000, ......}
• R = (00)*
Identities for regular expression –
• There are many identities for the regular expression. Let p, q and r are regular expressions.
• ∅+r=r
• ∅.r= r.∅ = ∅
• ∈.r = r.∈ =r
• ∈* = ∈ and ∅* = ∈
• r+r=r
• r*.r* = r*
• r.r* = r*.r = r+.
• (r*)* = r*
• ∈ +r.r* = r* = ∈ + r.r*
• (p.q)*.p = p.(q.p)*
• (p + q)* = (p*.q*)* = (p* + q*)*
• (p+ q).r= p.r+ q.r and r.(p+q) = r.p + r.q
Regular grammar
• Regular grammar is a type of grammar that describes a regular language.
• A regular grammar is a mathematical object, G, which consists of four
components, G = (V, T, P, S), where
• V: non-empty, finite set of non-terminal/variable symbols,
• T: a finite set of terminal symbols, or alphabet, symbols,
• P: a set of grammar rules, each of one having one of the forms
• A ⇢ aB
• A⇢ a
• A ⇢∈, Here ∈=empty string, A, B ∈ N, a ∈ ∑
• S ∈ N is the start symbol.
Regular grammar
• ∑ = {a,b}
• Initial state(q0) = A
• Final state(F) = B
• The RLG corresponding to FA is
• A ⇢ bB
• B ⇢ ∈/aB/bB
• The above grammar is RLG, which can be written directly through
FA.
• For converting the RLG into LLG for language L, the following
procedure needs to be followed:
• Step 1: Reverse the FA for language L
• Step 2: Write the RLG for it.
• Step 3: Reverse the right linear grammar.
• after this we get the grammar that generates the language that
represents the LLG for the same language L.
• L=set of all strings over input symbols a and b which start with b.
We are converting it into LLG.
• Step1: The reversal of FA is
• Start state: The first production state is known as the start state.
• Final state: All the states which end up with terminals without
following any further non-terminal.
• Example:
• In this example, we have the right linear grammar for language L. This
grammar shows all the strings which end with 0.
• X → 0X / 1Y / 0Y
• Y→∈
• So the finite automata which correspond to right linear grammar are
described as follows:
• Here we will begin with variable X and use its production like this:
• The production X → 0X means that when the transition gets '0' as an
input symbol, then state transition will always remain in the same state X.
• The production X → 1Y means that when the transition gets '1' as an
input symbol, then the state transition will go to state Y from state X.
• The production X → 0Y means that when the transition gets '0' as an
input symbol, then the state transition will go to state Y from state X.
• The production Y → ∈ means that this state does not require any type of
state transitions. In the corresponding FA (finite automata), this type of
production would be the final state because its RHS is terminal.
• So for the corresponding right linear grammar, the final NFA
(nonfinite automat) is described as follows:
• There are two Pumping Lemmas (PL), which are defined for Regular
Languages and Context - Free Languages.
• Pumping lemma for Regular languages
• It gives a method for pumping (generating) many substrings from a
given string.
• In other words, we say it provides means to break a given long input
string into several substrings.
• Lt gives necessary condition(s) to prove a set of strings is not regular.
Theorem
• For any regular language L, there exists an integer P, such that for all
w in L
• |w|>=P
• We can break w into three strings, w=xyz such that.
• (1)lxyl < P
• (2)lyl > 1
• (3)for all k>= 0: the string xykz is also in L
Application of pumping lemma
•There are two Pumping Lemmas (PL), which are defined for Regular
Languages and Context - Free Languages