0% found this document useful (0 votes)
103 views6 pages

FLAT Regular Languages Expressions

The document discusses regular languages and regular expressions. It provides examples of regular languages and explains that regular languages can be recognized by a finite automaton like a DFA or NFA. It then defines regular expressions recursively, covering base cases like the empty set and single symbols, and operations like concatenation, union, and Kleene star. Examples are provided to illustrate the meaning and languages of various regular expressions. Finally, it states the theorem that regular expressions correspond precisely to regular languages, meaning any regular language has a corresponding regular expression and vice versa.

Uploaded by

CS-6 GITAMHYD
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
103 views6 pages

FLAT Regular Languages Expressions

The document discusses regular languages and regular expressions. It provides examples of regular languages and explains that regular languages can be recognized by a finite automaton like a DFA or NFA. It then defines regular expressions recursively, covering base cases like the empty set and single symbols, and operations like concatenation, union, and Kleene star. Examples are provided to illustrate the meaning and languages of various regular expressions. Finally, it states the theorem that regular expressions correspond precisely to regular languages, meaning any regular language has a corresponding regular expression and vice versa.

Uploaded by

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

Module 2: Regular Languages, Regular Expressions

Lecture notes by Dr. K S Sudeep

Regular language: A ‘regular language’ is a language that can be recognized by


a finite automaton (DFA or NFA, it does not matter. We know a DFA is an NFA,
and for any NFA there is an equivalent DFA).

Examples:
L = All strings of even length,
L’ = All strings that end in a 1,
L1 = {w: w contains 001 as a substring} xxxx001yyyy
L2 = {w: w contains 001 as a subsequence} 010101 also contains 001 as a
subsequence,
L3 = strings that contain at least one 1
L4 = strings whose length is divisible by 3.
L5 = {w : length of w, when divided by 3, gives remainder 1}
L6 = {w: there are an even number of zeroes after the last 1 in w}

 Why are all these regular languages?


Simple: For all these languages, we can design a DFA (NFA) recognizing the
language (which says Yes on all strings in the language, says NO on other strings).

Concept of Expressions
 0* is an ‘expression’ that refers to a string that contains any number of
zeroes. i.e., the string can be empty string ε, or 0, 00, 000, ….
 0*10* is an ‘expression’ that means a string that contains exactly one 1.
Here, 0* means any number of consecutive zeroes (as a block). So the
string can be 0100, 10, 0001, 0010000, ….
We now define ‘regular expressions’ in a way that they correspond exactly to
regular languages, or they are expressions that capture regular languages. How?

Regular expressions: We define it recursively.


Base cases (or terminal cases):
1. Empty set Ø, empty string ε are regular expressions.

L (Ø) = Ø, or {}. No strings in this language. Ø: no strings


(Can you give a DFA for this language?)

L(ε) = {ε}, this is different from {}.


We can design a DFA for this language also.
2. If a is in the input alphabet in \Sigma, then ‘a’ is a regular expression.
It corresponds to the language (set) L(a) = {a}. Example, 0. L(0) = {0}.
It contains only one string, with a single symbol ‘a’.

(Inductive or recursive part of the definition starts here)

3. If A is a regular expression, A* is also a regular expression. A* means A


repeated (concatenated) 0 or more times. Example: 0* or 1*.
0* means ε, 0, 00, 000, ….

4. If A is a regular expression and B is a regular expression, then the


following are regular expressions.
(4.1) A ◦ B (A concatenation B), sometimes also written as AB.
Example: 0 ◦ 1 = 01, 0* ◦ 1* (or 0*1*), 0*1, 0*10*1.. these are all regular
expressions.
(4.2) A + B is a regular expression. Here, + means the union.
L(A+B) = L(A) U L(B).

Example: 0 + 1. The language here is {0} U {1} = {0, 1}.


Similarly, for the expression 01 + 10, the corresponding set is {01, 10}.
We say L(01+10) = {01, 10}.
L(0*1 + 10*) = {w of the form 0*1} U {w of the form 1*0}

5. If A is a regular expression, then (A) is also a regular expression.

 Understanding the meaning of regular expressions: some examples


(i) 0* means empty string, 0, 00, 00, … and so on, so

(01)*  what does this mean?

A string in which (01) concatenated with itself zero or more number


of times. Empty string, 01, 0101, 010101, ….. (any finite length string like this).

(ii) What do you understand by (0+1)*?

a string in (0+1) followed by another string in (0+1) followed by ….. (0 or more


number of times)  what are the strings? Or, what is the language of (0 + 1)*?

 w1 ◦ w2 ◦ … ◦ wk, where each wi is in {0, 1}, where k= 0, 1, 2, … (any non-


negative integer)
These are: Empty string ε, 0, 1, 00, 01, 10, 11, 000, 001, 010, …
In fact, it just means any string on the alphabet of zeroes and ones
(including empty string ε).
(iii) Now, look at the expression 0 + 1*

If we write it as 0 + 1*, it is different from by (0+1)*, as if we do not put brackets


or parenthesis, * applies on 1 only. Paranthesis makes it clear where the *
applies, without any scope for confusion.

L(0 + 1*) = L(0) U L(1*) = {0} U {empty string, 1, 11, 111, ….} = {ε, 0, 1, 11, 111..}
(iv) Reg. expression B = 0 + (11 ◦ 001)
Here, concatenation (or dot) operation ◦ has more precedence over +.
B = 0 + 11 ◦ 001, it means B = 0 + (11 ◦ 001) = 0 + 11001
L(B) = {0} U {11001} = {0, 11001}

(v) C = 0 ◦ 1*. What do you understand as L(C)?


This means 0 ◦ (1*), as * has more precedence over ◦.
L(C) = {0, 01, 011, 0111, …}
If we want 01 repeated one or more times, we must write (0 ◦ 1)*.
Or we can write it as (01)*.

 Precedence of operators in regular expressions (Highest to lowest)


*, ◦ (concatenation or dot), then + (union operation or plus).
If we have brackets or parenthesis, it avoids confusion, as they make it
clear the content inside brackets are to be computed first.

(vi) D = (0 ◦ 1)* means (01)*, which means 01 repeated / concatenated


0 or more times.
L(D) = {ε (empty string), 01, 0101, 010101, ….}

(vii) F = (00 + 110)* What is L(F)? What strings does it represent?


(Hint: Remember what strings were present in (0+1)*?)

This can be thought of as G*, where L(G) = {00, 110}

L(F) = L(G*) contains empty string, 00, 0000, 110110, ….

But that is not all.


00 ◦ 110 = 00110 is also in L(G*), 110 ◦ 00 = 11000 is also in it.
In fact, any number of '00' blocks and '110' blocks appended together, in
any order + the empty string.

(viii) Regular expression A = (00 + 110)* + 11 ◦ 001


What are the set of strings corresponding to A?
L(A) = {ε, 00, 110, 00◦00, 110◦110, 00◦110, 110◦00, 110◦00◦00,
00◦110◦00, …} U {11001}

Theorem: Regular expressions correspond to regular languages.


In other words, the language of any regular expression R has a DFA A
recognizing L(R), and any DFA A has an equivalent regular expression R
such that L(A) = L(R).

Proof:

Part 1: Given a regular expression R, how to construct an equivalent DFA


A that recognizes L(R)?

Let us start with the base cases.


1. R = Ø, or R = ε, in both these cases we can design a corresponding DFA.
The state diagrams are given below.

DFA AØ
Verify that this is a DFA that does not accept any string. In other words, the
language of this DFA is Ø, or the empty set.

DFA Aε

The DFA Aε accepts only the empty string, ε. It says NO on all other strings.

2. The next case is expressions of the form R = a. L(R) = {a}, this also has an
equivalent DFA (or an NFA). What is it?
For example, R = 0. L(R) = {0}, it has only one string, it is a single 0.

You might also like