0% found this document useful (0 votes)
24 views79 pages

Toa Lec 4

Uploaded by

shariqqayyum612
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)
24 views79 pages

Toa Lec 4

Uploaded by

shariqqayyum612
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/ 79

INTRODUCTION OF

AUTOMATION
L A G

Language Automata Grammer


SYMBOL
 A symbol is defined as a basic, indivisible unit or character that forms part

of an alphabet, which is a set of symbols. Symbols are used to build strings,


which are sequences of these symbols. Automata process input strings
consisting of symbols from a given alphabet.

Example of Symbols:
 In programming, an alphabet could be made up of any characters, such as

Σ = {a, b, c, ..., z, 0, 1, 2, ..., 9, +, -, *, /}, where each element is a


symbol.
ALPHABET
 An alphabet is a finite set of symbols from which strings are formed.
These symbols, often called letters, are the building blocks for defining the
input that an automaton processes. The alphabet is typically denoted by
the Greek letter Σ (Sigma).
 An alphabet is a finite, non-empty set of symbols.
 Each symbol in the alphabet is a unique, indivisible unit.
 An alphabet is the basis for constructing strings (finite sequences of
symbols), which form the input for automata.
Examples of Alphabets:
 Binary Alphabet, Alphabet of Letters etc.
STRING
 a string (also called a word) is a finite sequence of symbols taken from a
defined alphabet.
 A string is an ordered sequence of symbols from an alphabet Σ.
 The symbols in the string are placed in a specific order, and the length of the
string is the number of symbols it contains.
String Length:
 The length of a string is the number of symbols it contains. It is denoted as |
w|, where w is the string.
 Empty String (ε): The empty string is a special string that contains no symbols
at all. It is denoted by ε (epsilon). The length of the empty string is always
zero.
|ε| = 0
CONT.
Concatenation:
 Concatenation is the operation of joining two or more strings together to
form a new string.
 Example: If w₁ = "ab" and w₂ = "ba", the concatenation of w₁ and w₂ is w₁w₂
= "abba".
Substring:
 A substring is any contiguous sequence of symbols that appears within a
larger string.
 Example: In the string "automaton", "tom" is a substring of "automaton".
 Examples of Strings:

• For Σ = {a, b}:


• Valid strings: "a", "ab", "bba", "abab"
• Invalid strings: "abc" (because 'c' is not in the alphabet Σ).
LANGUAGE
 a language is a set of strings formed from an alphabet. Languages are one
of the fundamental concepts in formal language theory, and automata are
used to recognize or generate these languages. A language can be finite
or infinite, depending on the rules that define it.
 A language is a subset of all possible strings over a given alphabet
(denoted as Σ).
 Formally, if Σ is an alphabet, a language L is a set of strings, where each
string is composed of symbols from Σ.
L⊆Σ ∗
Here, Σ* (called the Kleene star of Σ) represents the set of all possible strings
(including the empty string) that can be formed using symbols from the
alphabet Σ.
TYPES OF LANGUAGES
Regular Languages:
 Recognized by Finite Automata (both deterministic and non-deterministic).

 Can be described by regular expressions.

Examples:
The set of all strings over Σ = {a, b} where the string contains exactly one
'a' (e.g., {"a", "ba", "ab"}).
Context-Free Languages (CFLs):
• Recognized by Pushdown Automata (PDAs).
• Described by context-free grammars (CFGs).

Context-Sensitive Languages:
• Recognized by Linear Bounded Automata (LBAs).
• Described by context-sensitive grammars.
Finite Automata
• In FA we can represent language in form of diagram or
(FA)
graphically.

• FA are also known as:


• Finite Machine (FM)
• Finite Automatic Machine (FAM)
• Finite State Machine (FSM)
Formal Language Definitions
Why need formal definitions of language
Define a precise, unambiguous and uniform interpretation
Communication with machines
Regular ExpressionFormal Language notation/definition

Tell how to generate words of that language


Tell which words belong to this language
Can this be automated?
REs define a language and FAs accept (or reject ) them
Finite Automaton

A finite set of transitions that tell for each state and for each
letter of the input alphabet which state to go to next
Applications of Finite Automata
Application
Area Description
Language Processing Used in email filters and smart assistants like Alexa, Siri, and Google Assistant.

Compiler Construction Translates high-level programming languages into machine code.

Computer Networks Underlies the design of network protocols such as HTTP and HTTPS.

Video Games Manages game mechanics and AI, as seen in games like Warcraft 3.

Designs digital circuits in devices such as fans, refrigerators, and washing


Digital Circuit Design machines.

Biomedical Problem Solving Utilized in medical imaging technologies like X-ray diffraction and tomography.
CONTEXT FREE
GRAMMAR(CFG)
 a grammar is a formal set of rules that define how strings in a language are generated.
Grammars are essential for describing the syntax of programming languages, natural
languages, and other formal systems.
 A grammar is a 4-tuple G = (N, Σ, P, S), where:
 N (Non-terminal symbols): A finite set of symbols, called non-terminals, that represent
intermediate constructs or variables used in generating the strings of the language.
 Σ (Terminal symbols): A finite set of symbols, called terminals, that form the actual strings of
the language.
 (N∩Σ=∅)
 P (Production rules): A finite set of production rules, which describe how the non-terminal
symbols can be replaced by terminals or other non-terminals. Each production rule has the

𝐴→𝛼
form:

 Where A is a non-terminal, and α is a string of terminals and/or non-terminals. The rule states
that the non-terminal A can be replaced by α.
 S (Start symbol): A special non-terminal symbol, called the start symbol, from which string
generation begins.
Example of a Grammar:
 Σ = {a, b} (terminals are 'a' and 'b’),
 P = {S → aSb, S → ε} (the production rules),
 S is the start symbol.

This grammar generates strings where the number of 'a's is equal to the
number of 'b's. For example:
S → ε (The empty string ε is a valid string in the language).
S → aSb → ab (One 'a' followed by one 'b’).
S → aSb → aaSbb → aabbb (Two 'a's followed by two 'b's).
RE to CFG Conversion (Examples)
1) RE= 2) RE= (a+b) (a+b) 4) RE= (a+b) (aa+bb)
a+b S AA (a+b)
S ABA
A a|b
S or a|b A. a|b
S a 3) RE= (a+b)a +
B. YY |
S b ab ZZ
S
or Y. a
X Y
S X X Z. b
JK
|Y
J. a|b
X. a K. a
Y. b Y
KB
CFG Derivation
• Derivation is generation of string from grammar.

• We can use CFG derivation to find out:


• Which string is produced by grammar
• specific string is generated by grammar or not

• We can draw derivation tree to find out string produced by


grammar
CFG Derivation (Example)
• Find out the string generated by given CFG
• RE (bb)*a* S
• CFG S XY X Y

X bbX|ɛ bb ε aY ε
X
Y aY|ɛ aY ε
bb ε
X
string generated by given grammar
will be: bbX
ε
aY
ε
bbbbbbaaa
ε ε
In general: b2n an ; n>=1
CFG Derivation (Example)
• Find out is “baab” valid string of given
CFG?
S A B A
S a|b B A
S a|b YY|ZZ A
S a|b aa|bb A
S a|b aa|bb a|b

Yes, baab is valid string for given grammar


FA (formal
definition)
 A finite automaton is a 5-tuple (Q,,,q0,F), where

1. Q is a finite set called the states. (e.g. q0,


q1,q2,q3..)

  is a finite set called the alphabet. (e.g.  =


{a,b})

  : Transition/movement

4. q0 is the start state (initial state)

5. F (final states).
FA Tuples
 q0definition
(start state or initial state)

• Every finite automata always start with q0

• In FA there will be only one initial state

• It is represented by: q0 or
Cont

 FA (Final state)
• In FA the minimum number of final state should be 1 and maximum
number of final states can be more then 1.

• It means we may have more then 1 finial states in FA.

• At final state machine may stop or may not stop depend on


our language (input).

It is represented by: + OR
Cont

In Finite Automata (FA), Q is the set of all possible states that
the automaton can be in at any given time.
Formally:
Q={q0,q1,q2,…,qn} where:
• q0 is the start state (or initial state)
• F⊆Q is the set of final (accepting) states
• The rest are intermediate states the automaton may pass
through

  : Transition/movement
• Transition or movement is represent with sign.
Types of FA

• There are two main types of FA


• NFA (non deterministic finite automata)
• DFA (deterministic finite automata)
NF
A
• NFA stands for non-deterministic finite automata.

• The finite automata are called NFA when there exist many paths for
specific input from the current state to the next state.
• In NFA dead configuration is allowed.
• In other words, the exact state to which the machine moves cannot
be determined. Hence, it is called Non-deterministic Automation.

• In NFA empty state transition is also allowed


FORMAL DEFINITION OF
NFA:
 An NFA is defined by a 5-tuple (Q, Σ, δ, q₀, F), where:
 Q: A finite set of states.
 Σ: A finite alphabet (the set of input symbols).
 δ (transition function): A transition function that maps a state and an input
symbol to a set of possible next states.
δ:Q×Σ∪{ε}→2^Q
 Here, 2^Q represents the power set of Q (the set of all subsets of Q), because
the NFA can transition to multiple possible states for a single input or epsilon (ε)
transition.
 q₀: The start state, an element of Q, where the NFA begins.
 F: A set of accepting states, a subset of Q. If the NFA reaches any state in F after
reading the entire input, it accepts the input string.
NFA
a a
examples
We have two choices

q1 q2

q0
q3
First
Choice
a a
All input is
consumed
q1 q2
“accept”
q0

q3
26
Second
Choice
a a

q1 q2

q0

q3
27
Second
a a Choice
Input cannot be
consumed
q1 q2
Automaton
q0 Halts
q3
“reject”
28
An NFA accepts a string:
if there is a computation of the
NFA that accepts the string

i.e., all the input string is processed and


the automaton is in an accepting state

29
aa is accepted by the
NFA:

“accept
q1 ” q2 q1 q2

q0 q0
q3 q3 “reject
because ”
this this
computatio computation
is 6

ignored
2

n accepts
An NFA rejects a string:
if there is no computation of the
NFA that accepts the string.

For each computation:


• All the input is
consumed and the automaton
is in a non final state

OR
Rejection
example

q1 q2

q0

q3
32
First
Choice

“reject

q1 q2

q0

q3
33
Second
Choice

q1 q2

q0

q3
34
Second
Choice

q1 q2

q0

q3
35
Another Rejection
example

q1 q2

q0

q3
36
First
Choice

q1 q2

q0

q3
37
First
Choice

Input cannot be consumed


q1 q2
“reject”
q0
Automaton
q3 halts

38
Second
Choice

q1 q2

q0

q3
39
Second
Choice

Input cannot be consumed


q1 q2
Automaton
q0 halts
q3 “reject

40
is rejected by the
NFA:
“reject
q1 q2 ”
q1 q2

q0 q0
q3 “reject q3

All possible computations lead to rej e 7 3

ction
is rejected by the
NFA:

“reject
q1 ” q2 q1 q2

q0 q0
q3 q3 “reject

All possible computations lead to rej e7 4

ction
Language accepted: L

{aa}
q1 q2

q0

q3
Lambda
Transitions

q0 q1 q2 q3
a a

q0 q1 q2 q3
a a

q0 q1 q2 q3
input tape head does not
move
a a

q0 q1 q2 q3
all input is consumed

a a

“accept

q0 q1 q2 q3

String aa is
Rejection
Example

a a a

q0 q1 q2 q3
a a a

q0 q1 q2 q3
(read head doesn’t
move)
a a a

q0 q1 q2 q3
Input cannot be consumed

a a a

Automaton halts
“reject

q0 q1 q2 q3

String is
rejected
Language accepted: L

{aa}

q0 q1 q2 q3
Another NFA
Example

a q1 b q2 q3
q0
a b

a q1 b q2 q3
q0
a b

a b q2 q3
q0 q1
a b

“accept
a b ”
q0 q1 q2 q3
Another
String
a b a b

a b
q0 q1 q2 q3
a b a b

a b
q0 q1 q2 q3
a b a b

a b
q0 q1 q2 q3
a b a b

a b
q0 q1 q2 q3
a b a b

a b
q0 q1 q2 q3
a b a b

a b
q0 q1 q2 q3
a b a b

“accept
a b ”
q0 q1 q2 q3
NFA
Examples
• Draw NFA for RE =
a
a
q0 q1
NFA Examples

• Draw NFA for RE = a +


b
a
q0 q1
b
NFA Examples

• Draw NFA for RE =


ab
a b
q0 q1 q2
NFA Examples
 Draw NFA for string that end with ‘aa’ defined over ∑ = {a,
b}.
• First we need to write its RE
RE
(a+b)*aa
a, b
a a
q0 q1 q2
NFA
Examples
 Draw NFA for all strings defined over ∑ =
{a}
• We have only one letter in given alphabet.
• So language should be {^, a, aa,aaa,aaaa….}
RE = (a)*
a

q0
NFA Examples
 Draw NFA for all strings that starts with ‘a’ and end with ‘bb’,
defined over alphabet ∑ = {a, b}.
• The string that will be generated according to given condition may be
of following type
S= abb
= a [^, a, b, ab, aaa,bbb…] bb
RE = a (a+b)* a, b
bb
a b b
q0 q1 q2 q3
NFA
Examples
 Draw a NFA for all possible strings start and end with same letter
defined over alphabet ∑ = {a, b}.
• Given condition means if string start with ‘a’ then it also end with ‘a’ or if
it start with ‘b’ then it also end with ‘b’
a, b
• L1= { aa}
a
= {a q1 q2
(a+b)*a} a

• L2= {bb} q0 b
b
= {b (a+b)*b} q3

a, b
RE= a(a+b)*a + b (a+b)*
b
NFA
Examples
 Draw a NFA for all possible strings start and end with different
letter defined over alphabet ∑ = {a, b}.
• Given condition means if string start with ‘a’ then it should end with ‘b’ or
if it start with ‘b’ then it should end with ‘a’
a, b
• L1= { ab}
b
= {a q1 q2
(a+b)*b} a

• L2= {ba} q0 a
b
= {b (a+b)*a} q3

a, b
RE= a(a+b)*b + b (a+b)*
a
Draw NFA for all the strings that contains ‘aa’, defined over alphabet ∑ = {a,
b}.
• Draw NFA for string that contain at least one ‘a’ and end with ‘b’
defined over alphabet ∑ = {a, b}.

Please design an NFA with input alphabet ∑ = {0, 1} that


accepts all the strings that end with 01.

Construct an NFA with ∑ = {0, 1} in which each


string must contain “double ‘1’ is followed by single
‘0’.
Design an NFA with ∑ = {0, 1} such that every string
includes the substring 1101.
NFA
 Examples
Draw NFA for all the strings that contains ‘aa’, defined over alphabet ∑ =
{a, b}.
• According to given condition in our language there should be ‘aa’ in every
string so our defined language may be be of following type
• L= { aa, aaa, abaa, baab, aabba, bbbabaa….}
• AS we see in our language “aa” may be in start or in end or in between any
letter defined over alphabet ∑ = {a, b}.
• RE= (a+b)* aa (a+b)*
a, b
a, b

a a
q0 q1 q2
NFA
• Draw NFA for string that contain at least one ‘a’ and end with ‘b’
Examples
defined over alphabet ∑ = {a, b}.

• Language will be L= {ab }


• RE = { (a+b)* a (a+b)* b}

a, b a, b

a b
q0 q1 q2

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