0% found this document useful (0 votes)
1K views59 pages

Lecture#03, FA, Union, Complement, Intersection, Concatenation, Kleene Star

This document discusses finite automata and regular languages. It covers topics like regular expressions, finite and regular languages, finite automata, transition tables, and creating finite automata to accept various languages based on operations like union, intersection, concatenation, and Kleene star. It provides examples of different types of regular languages and exercises to create finite automata for specified languages over alphabets.

Uploaded by

Azka Aziz
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)
1K views59 pages

Lecture#03, FA, Union, Complement, Intersection, Concatenation, Kleene Star

This document discusses finite automata and regular languages. It covers topics like regular expressions, finite and regular languages, finite automata, transition tables, and creating finite automata to accept various languages based on operations like union, intersection, concatenation, and Kleene star. It provides examples of different types of regular languages and exercises to create finite automata for specified languages over alphabets.

Uploaded by

Azka Aziz
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/ 59

THEORY OF AUTOMATA

Lecture#03
Finite Automata, Union of Languages, Intersection of Languages, Complement of a
Language, Kleene’s Star of a Language, Concatenation of Languages
Lecture Contents
 Regular Languages
 Finite Languages
 Relation between Finite & Regular Languages
 Finite Automaton
 Identifying Languages accepted by FA
 Transition Table for FA
 Creating FA to accept a Language
 Creating FA to accept a Finite Language
 Creating FA for Union of Two Languages
 Creating FA for Intersection of Two Languages
 Creating FA for Negation of a Language
 Creating FA for Concatenation of Two Languages
 Creating FA for Cleene’s Star of a Language
Regular Expressions
If r1 = (aa + bb) and r2 = ( a + b) then
r1+r2 = (aa + bb) + (a + b)
r1r2 = (aa + bb) (a + b) = (aaa + aab + bba + bbb)
(r1)* = (aa + bb)*
Regular Languages
Definition
The language generated by any regular expression is called
a regular language
It is to be noted that if r1, r2 are regular expressions,
corresponding to the languages L1 and L2 then the
languages generated by
1. r1 + r2
2. r1 r2( or r2 r1) and
3. r1 *( or r2*)
are also regular languages
Regular Languages
Note
It is to be noted that if L1 and L2 are expressed by r1and r2,
respectively then the language expressed by
1) r1+ r2, is the language L1 + L2
2) r1r2, is the language L1L2, of strings obtained by prefixing
every string of L1 with every string of L2
3) r1*, is the language L1*, of strings obtained by
concatenating the strings of L1, including the null string
Finite Languages
A language is said to be a finite language if it contains finite
words into it

e.g. Language (L1) of all words of length 2 over alphabet Σ = {a,b}


Total Number of words in L1 are?

Few examples to be quoted:::::


Regular Languages; R1+R2
If r1 & r2 be two regular expressions of languages L1 & L2
respectively then “Is r1 + r2 a regular Expression?”

YES
What language is represented by r1+r2?
According to set theory: L1UL2 (Union of both L1 & L2)
Example: if r1 = (a+b)(a+b) and r2 = (a+b)
Then
r1 + r2 = (a+b)(a+b) +(a+b)
i.e. r1 + r2 = aa + ab + ba + bb + a + b
Regular Languages; R1R2
If r1 & r2 be two regular expressions of languages L1 & L2
respectively then “Is r1r2 a regular Expression?”

YES
What language is represented by r1r2?
Language of all words formed by concatenation of
words from L1 & L2
Examples to be discussed
Regular Languages; R1R2
For Example:
If r1 = (a+b)(a+b), r2 = (a+b)
Then r1r2 = (a+b)(a+b)(a+b)
i.e. r1r2=(aa+ab+ba+bb)(a+b)
= (aaa+aba+baa+bba+aab+abb+bab+bbb)

r1r2, , is the language L1L2, of strings obtained by prefixing every


string of L1 with every string of L2
Regular Languages; (R)*
If r1 be a regular expression of languagesL1 then “Is (r1)* a
regular Expression?”

YES

What language is represented by (r1)* ?


r1*, is the language L1*, of strings obtained by
concatenating the strings of L, including the null string
Examples to be discussed
Regular Languages; (R)*
For Example:
If r1 = (a+b)(a+b)
Then (r1)* = ((a+b)(a+b))*
= ^ + aa + ab + ba + bb + aaaa + abaa + baaa+ bbaa+
…….
All Finite Languages Are Finite
Example
Consider the language L, defined over Σ = {a,b}, of
strings of length 2, starting with a, then
L = {aa, ab}, may be expressed by the regular expression
aa+ab. Hence L, by definition, is a regular language.
Introduction to Finite Automaton
Consider a board game in which all moves are
based on dice outcomes. Player keeps throwing
dices and outcomes of dices decides the game
progress. After showing of certain outcomes,
game ends (Player wins) i.e. winning of player
depends on sequence of dice outcomes. This
structure of game can be considered as Finite
Automaton.
Finite Automaton: Definition
A Finite automaton (FA), is a collection of the followings:
1. Finite set of input letters (Σ) from which input strings are
formed e.g. Σ = {a, b}
2. Finite number of states, having one initial and final states
e.g. x, y, z be the states where x is initial state and z is
final state
3. Finite set of transitions i.e. for each state and for each
input letter there is a transition showing how to move from
one state to another
Identify the Language Σ = {0,1}

1,0

If above machine accepts only strings with input ending in a double


circle, what kind of machine is it? (What is pattern in strings that
above machine accepts?)
Identify the Language Σ = {0,1}

1
1,0

0,1

If above machine accepts only strings with input ending in a double circle,
what kind of machine is it? (What is pattern in strings that above machine
accepts?)
Identify the Language Σ = {0,1}
0,1 1,0
1

0
1,0

If above machine accepts only strings with input ending in a double


circle, what kind of machine is it? (What is pattern in strings that
above machine accepts?)
Identify the Language a
Σ = {a,b}
b

a b
b
a
a

If above machine accepts only strings with input ending in a double


circle, what kind of machine is it? (What is pattern in strings that
above machine accepts?)
Identify the Language a
Σ = {a,b}
b

a b
b
a
a

If above machine accepts only strings with input ending in a double


circle, what kind of machine is it? (What is pattern in strings that
above machine accepts?)
Identify the Language Σ = {a,b}

b
a

a b

b a
b a

If above machine accepts only strings with input ending in a double


circle, what kind of machine is it? (What is pattern in strings that
above machine accepts?)
Finite Automaton
Think of Automaton as a machine that:
Runs on input (letters of words in this case)
Changes its state with every input
When input ends then current state would tell whether input
string belongs to FA’s language or not
Finite Automaton Transitions: Transition Table
Example
Σ = {a,b}
States: x, y, z where x is an initial state and z is final state.
Transitions:
1. At state x reading a, go to state z
2. At state x reading b, go to state y
3. At state y reading a, b go to state y
4. At state z reading a, b go to state z
Finite Automaton Transitions
Old State New State
Reading ‘a’ Reading ‘b’
x- z+ y
y y y
z z+ z+
a,b
Which language is represented by this FA? y
b
x–
a,b
a
z++
Finite Automaton Transitions
 The above transition diagram is an FA accepting the
language of strings, defined over Σ = {a, b}, starting with
a
 It may be noted that this language may be expressed by
the regular expression a(a + b)*
Finite Automaton: Exercises
Create transition table and FAs for following languages over alphabet Σ =
{a,b}
1. Language with no words
2. Language of all words
3. Language of even / odd length words
4. Language of all words starting with a
5. Language of all words not starting with a
6. Language of all words ending with a
7. Language of all words not ending with a
8. Language of all words starting and ending with same letter
Finite Automaton: Exercises
Create transition table and FAs for following languages over alphabet Σ =
{a,b}
1. Language of all words starting and ending with different letters
2. Language of all words containing substring abb
3. Language of all words containing substring abb or baa
4. Language of all words not containing substring abb
5. EVEN-EVEN / ODD-ODD / EVEN-ODD / ODD-EVEN
6. Language of all words with count of ‘a’ as multiple of three
7. Language of all words with count of ‘a’ as not multiple of three
8. Language of all words with a as 2nd letter
Finite Automaton: Exercises
Create transition table and FAs for following languages over alphabet Σ =
{a,b}
1. Language of all words with ‘a’ as 2nd last letter
2. Language of all words where ‘a’ can only appear on even positions; if at all
3. Language of all words where ‘a’ never follows ‘b’
4. Language of all words where ‘a’ never precedes ‘b’
5. a*b*
FA corresponding to Finite Languages
1. Create FA of language over Σ = {a,b} defined as L = {ab, ba, abb}
2. Create FA of language over Σ = {a,b} defined as L = {Λ, b, ab, bb}
3. Create FA of language over Σ = {a,b} defined as L = {aa, bab, aabb, bbba}

How to do it?
Any Ideas????????
FA corresponding to Finite Languages
Simple idea!!!
1. Initiating from Start State, show two transactions from every state to
new states
2. Every new state that refers to the end of word(s) should be marked as
final state
3. When all words have been accepted then complete transitions on every
state (all letters of alphabet) to a new non-final state
That is It. You are done.
Union Theorem

Given two languages, L1 and L2, define the union of L1 and L2 as


L1  L2 = { w | w  L1 OR w  L2 }

Theorem: The union of two regular languages is also a


regular language
Union (of languages) Theorem

Proof Sketch: Let


F1 = (Q1, Σ, F1) be finite automaton for L1 and
F2 = (Q2, Σ, F2) be finite automaton for L2

What do we want to get?


We want to create FA that accepts all words from both languages L1 and L2
How should we proceed?
Ideas are welcome
Union (of languages) Theorem

Idea: Run both F1 and F2 at the same time!

Rule 1:
Q= Any state of resulting FA corresponds to pair of states
(one from F1 and other from F2)
Rule 2:
Starting state for resulting FA q0 is corresponding to starting state
of both FAs (F1 and F2)
Rule 3:
Any state in resulting FA is considered to be final state if any of two
or both corresponding FA states are final
Union (of languages) Theorem: (Demonstration)
Let L1 and L2 be two languages over such that Σ = {a,b}
L1 = “Language of all words having substring ab”
L2 = “Language of all words ending on a”
Corresponding FA’s are as follows

Union of above languages is a language that contains all words that are
either ending on a or having substring ab
Creating FA for Union of FA1 & FA2
Current State New State on Input = a New State on Input = b
Qz0 (Qx OR Q0) Qz1 (Qy OR Q1) Qz0 (Qx OR Q0)
Qz1 (Qy OR Q1) FINAL STATE Qz1 (Qy OR Q1) Qz2 (Qz OR Q0)
Qz2 (Qz OR Q0) FINAL STATE Qz3 (Qz OR Q1) Qz2 (Qz OR Q0)
Qz3 (Qz OR Q1) FINAL STATE Qz3 (Qz OR Q1) Qz2 (Qz OR Q0)
Creating FA for Union of FA1 & FA2 from Transition Table
Current State New State on Input = a New State on Input = b
Qz0 (Qx OR Q0) Qz1 (Qy OR Q1) Qz0 (Qx OR Q0)
Qz1 (Qy OR Q1) FINAL STATE Qz1 (Qy OR Q1) Qz2 (Qz OR Q0)
Qz2 (Qz OR Q0) FINAL STATE Qz3 (Qz OR Q1) Qz2 (Qz OR Q0)
Qz3 (Qz OR Q1) FINAL STATE Qz3 (Qz OR Q1) Qz2 (Qz OR Q0)

a b a
b
a
a b Qz3
Qz0 Qz1 Qz2
b
FA for Union FA1 & FA2 from Transition Table
 Same method should be followed to get FA for Union of two FAs
 Above method proves that there always FA available for Union of two
FAs (FAs for any arbitrary languages)
 Since every language that can be accepted by FA is regular, hence Union
language of any two regular language is always a Regular Language
Intersection (of languages) Theorem

Proof Sketch: Let


F1 = (Q1, Σ, F1) be finite automaton for L1 and
F2 = (Q2, Σ, F2) be finite automaton for L2

What do we want to get?


We want to create FA that accepts all words common to both languages L1
and L2

How should we proceed?


Ideas are welcome
Intersection(of languages) Theorem

Idea: Run both F1 and F2 at the same time!

Rule 1:
Q= Any state of resulting FA corresponds to pair of states
(one from F1 and other from F2)
Rule 2:
Starting state for resulting FA q0 is corresponding to starting state
of both FAs (F1 and F2)
Rule 3:
Any state in resulting FA is considered to be final state if only both
of corresponding FA states are final
Intersection (of languages) Theorem: (Demonstration)
Let L1 and L2 be two languages over such that Σ = {a,b}
L1 = “Language of all words having substring ab”
L2 = “Language of all words ending on a”
Corresponding FA’s are as follows

Intersection of above languages is a language that contains all words that


end on a and have substring ab
Creating FA for Intersection of FA1 & FA2
Current State New State on Input = a New State on Input = b
Qz0 (Qx OR Q0) Qz1 (Qy OR Q1) Qz0 (Qx OR Q0)
Qz1 (Qy OR Q1) Qz1 (Qy OR Q1) Qz2 (Qz OR Q0)
Qz2 (Qz OR Q0) Qz3 (Qz OR Q1) Qz2 (Qz OR Q0)
Qz3 (Qz OR Q1) FINAL STATE Qz3 (Qz OR Q1) Qz2 (Qz OR Q0)
Creating FA for Intersection of FA1 & FA2 from Transition
TableState
Current New State on Input = a New State on Input = b
Qz0 (Qx OR Q0) Qz1 (Qy OR Q1) Qz0 (Qx OR Q0)
Qz1 (Qy OR Q1) Qz1 (Qy OR Q1) Qz2 (Qz OR Q0)
Qz2 (Qz OR Q0) Qz3 (Qz OR Q1) Qz2 (Qz OR Q0)
Qz3 (Qz OR Q1) FINAL STATE Qz3 (Qz OR Q1) Qz2 (Qz OR Q0)

a b a
b
a
a b Qz3
Qz0 Qz1 Qz2
b
FA for Intersection of FA1 & FA2 from Transition Table
 Same method should be followed to get FA for Intersection of two FAs
 Above method proves that there always FA available for Intersection of
two FAs (FAs for any arbitrary languages)
 Since every language that can be accepted by FA is regular, hence
Intersection language of any two regular language is always a Regular
Language
Negation of a Language

Proof Sketch: Let


F1 = (Q1, Σ, F1) be finite automaton for L1

What do we want to get?


We want to create FA that accepts all words that were not part of by L1
and reject all words that were part of L1

How should we proceed?


Ideas are welcome
Negation (of language) Theorem

Idea: Run both F1

Rule 1:
Q= Any state of resulting FA corresponds to exactly same
state in original FA (F1)
Rule 2:
Starting state for resulting FA q0 is corresponding to starting state
of original FA (F1)
Rule 3:
Any state in resulting FA will be final state if corresponding state in
original FA (F1) was not final and vice versa.
Negation (of language) Theorem: (Demonstration)
Let L1 be a language over such that Σ = {a,b}
L1 = “Language of all words having substring ab”
Corresponding FA is as follows

Intersection of above language is a language that contains all words not


having substring ab
Creating FA for Negation of FA1
Current State New State on Input = a New State on Input = b
Qz0 (Qx) FINAL STATE Qz1 (Qy) Qz0 (Qx)
Qz1 (Qy) FINAL STATE Qz1 (Qy) Qz2 (Qz)
Qz2 (Qz) Qz2 (Qz) Qz2 (Qz)
FA for Negation of FA1 from Transition Table
 Same method should be followed to get FA for Negation of one FA
 Above method proves that there is always FA available for Negation of
one FA (FA for any arbitrary languages)
 Since every language that can be accepted by FA is regular, hence
Negation language of any regular language is always a Regular
Language
Concatenation (of languages) Theorem

Proof Sketch: Let


F1 = (Q1, Σ, F1) be finite automaton for L1 and
F2 = (Q2, Σ, F2) be finite automaton for L2

What do we want to get?


We want to create FA that accepts all words resulted by concatenation of
words (1st part from L1 & 2nd from L2) from both languages L1 and L2

How should we proceed?


Ideas are welcome
Concatenation (of languages) Theorem

Idea: Run both F1 and F2 at the same time!

Rule 1:
Q= Any state of resulting FA can correspond to state of one FA
or two FAs (F1 and F2)
Rule 2:
Starting state for resulting FA q0 is corresponding to starting state
of one FA (F1) only
Rule 3:
Any state in resulting FA is considered to be final state if it matches
with final state of FA (F2) only
Concatenation(of languages) Theorem: (Demonstration)
Let L1 and L2 be two languages over such that Σ = {a,b}
L1 = “Language of all words having substring ab”
L2 = “Language of all words ending on a”
Corresponding FA’s are as follows

Concatenation of above languages is a language that contains all words


contain substring ab and also end on a
Creating FA for Concatenation of FA1 & FA2
Current State New State on Input = a New State on Input = b
Qz0 (Qx) Qz1 (Qy) Qz0 (Qx)
Qz1 (Qy) Qz1 (Qy) Qz2 (Qz OR Q0)
Qz2 (Qz OR Q0) Qz3 (Qz OR Q0 OR Q1) Qz2 (Qz OR Q0)
Qz3 (Qz OR Q0 OR Q1) FINAL STATE Qz3 (Qz OR Q0 OR Q1) Qz2 (Qz OR Q0)
Creating FA for Concatenation of FA1 & FA2 from Transition Table
Current State New State on Input = a New State on Input = b
Qz0 (Qx) Qz1 (Qy) Qz0 (Qx)
Qz1 (Qy) Qz1 (Qy) Qz2 (Qz OR Q0)
Qz2 (Qz OR Q0) Qz3 (Qz OR Q0 OR Q1) Qz2 (Qz OR Q0)
Qz3 (Qz OR Q0 OR Q1) FINAL STATE Qz3 (Qz OR Q0 OR Q1) Qz2 (Qz OR Q0)

a b a
b
a
a b Qz3
Qz0 Qz1 Qz2
b
FA for Concatenation of FA1 & FA2 from Transition Table
 Same method should be followed to get FA for Intersection of two FAs
 Above method proves that there is always FA available for
Concatenation of two FAs (FAs for any arbitrary regular languages)
 Since every language that can be accepted by FA is regular, hence
Concatenation language of any two regular language is always a
Regular Language
Kleene’s (of languages) Theorem

Proof Sketch: Let


F1 = (Q1, Σ, F1) be finite automaton for L1

What do we want to get?


We want to create FA that accepts all words resulted by applying Kleene
Star on all words from language L1

How should we proceed?


Ideas are welcome
Kleene (of languages) Theorem

Idea: Run words on F1

Rule 1:
Q = Any state of resulting FA will correspond to state of one
FA(F1)
Rule 2:
Starting state for resulting FA q0 is corresponding to starting state
of one FA (F1) only
Rule 3:
Any state in resulting FA is considered to be final state if it matches
with final state of FA (F1) only
Kleene’s Star Theorem: (Demonstration)
Let L1 be a language over such that Σ = {a,b}
L1 = “Language of all words exactly three b”
Corresponding FA is as follows

Kleene Star of above language is a language that contains all words


containing any multiple of three b i.e. 0 b, 3 b, 6 b, 9 b etc
Creating FA for Concatenation of FA1 & FA2
Current State New State on Input = a New State on Input = b
Qz0 (Qx) FINAL STATE Qz0 (Q0) Qz1 (Q1)
Qz1 (Q1) Qz1 (Q1) Qz2 (Q2)
Qz2 (Q2) Qz2 (Q2) Qz2 (Q3 OR Q0)
Qz3 (Q3 OR Q0) FINAL STATE Qz3 (Q3 OR Q0) Qz4 (Q4 OR Q1)
Qz4 (Q4 OR Q1) Qz4 (Q4 OR Q1) Qz5 (Q4 OR Q2)
Qz5 (Q4 OR Q2) Qz5 (Q4 OR Q2) Qz6 (Q4 OR Q3 OR Q0)
Qz6 (Q4 OR Q3 OR Q0) FINAL STATE Qz6 (Q4 OR Q3 OR Q0) Qz4 (Q4 OR Q1)
Creating FA for Kleene Starof FA1 from Transition Table
Current State New State on Input = a New State on Input = b
Qz0 (Qx) FINAL STATE Qz0 (Q0) Qz1 (Q1)
Qz1 (Q1) Qz1 (Q1) Qz2 (Q2)
Qz2 (Q2) Qz2 (Q2) Qz2 (Q3 OR Q0)
Qz3 (Q3 OR Q0) FINAL STATE Qz3 (Q3 OR Q0) Qz4 (Q4 OR Q1)
Qz4 (Q4 OR Q1) Qz4 (Q4 OR Q1) Qz5 (Q4 OR Q2)
Qz5 (Q4 OR Q2) Qz5 (Q4 OR Q2) Qz6 (Q4 OR Q3 OR Q0)
Qz6 (Q4 OR Q3 OR Q0) FINAL STATE Qz6 (Q4 OR Q3 OR Q0) Qz4 (Q4 OR Q1) a

Please create FA by using above Transition Table


FA for Kleene Star of FA1 from Transition Table
 Same method should be followed to get FA for Intersection of two FAs
 Above method proves that there is always FA available for Kleene Star
of one FA (FA for any arbitrary regular languages)
 Since every language that can be accepted by FA is regular, hence
Kleene Star language of any regular language is always a Regular
Language

You might also like