0% found this document useful (0 votes)
64 views14 pages

Formal Methods: Finite State Machine - Regular Expressions

This document discusses finite state machines and regular expressions. It begins by defining a finite state machine as a computation model that can simulate sequential logic and programs. Finite state machines generate regular languages and can be used to model problems in many fields. The document then provides examples of applications of finite state machines, including games, artificial intelligence, text parsing, and network protocols. It also defines regular expressions as patterns to match character combinations in strings and discusses how they are used. The remainder of the document provides more details on regular expressions, regular languages, alphabets, strings, and constructing finite automata from regular expressions.

Uploaded by

Status Life
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)
64 views14 pages

Formal Methods: Finite State Machine - Regular Expressions

This document discusses finite state machines and regular expressions. It begins by defining a finite state machine as a computation model that can simulate sequential logic and programs. Finite state machines generate regular languages and can be used to model problems in many fields. The document then provides examples of applications of finite state machines, including games, artificial intelligence, text parsing, and network protocols. It also defines regular expressions as patterns to match character combinations in strings and discusses how they are used. The remainder of the document provides more details on regular expressions, regular languages, alphabets, strings, and constructing finite automata from regular expressions.

Uploaded by

Status Life
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/ 14

FORMAL

METHODS
Lecture 7: Finite state machine –Regular Expressions

LECTURER: QURATULAIN
DEPARTMENT OF INFORMATION TECHNOLOGY
GOVERNMENT COLLEGE UNIVERSITY FAISALABAD
FINITE STATE MACHINE
MODELS

A finite state machine (sometimes called a finite state


automaton) is a computation model that can be implemented
with hardware or software and can be used to simulate
sequential logic and some computer programs.
Finite state automata generate regular languages. Finite state
machines can be used to model problems in many fields
including mathematics, artificial intelligence, games, and
linguistics.
FINITE STATE MACHINE
APPLICATIONS
• FSMs are used in games; they are most recognized for being utilized in artificial
intelligence, and however, they are also frequent in executions of navigating parsing
text, input handling of the customer, as well as network protocols.
• These are restricted in computational power; they have the good quality of being
comparatively simple to recognize. So, they are frequently used by software
developers as well as system designers for summarizing the performance of a difficult
system.
• The finite state machines are applicable in vending machines, video games, traffic
lights, controllers in CPU, text parsing, analysis of protocol, recognition of speech,
language processing, etc.
REGULAR EXPRESSIONS
• Regular expressions are patterns used to match character combinations in
strings
• The extensive pattern-matching notation of regular expressions enables you to
quickly parse large amounts of text to:
• Find specific character patterns.
• Validate text to ensure that it matches a predefined pattern (such as an email
address).
• Extract, edit, replace, or delete text substrings.
• Add extracted strings to a collection in order to generate a report.
• For many applications that deal with strings or that parse large blocks of text,
regular expressions are an indispensable tool.
ALPHABETS
An alphabet is specified by giving a finite set, !, whose elements are called symbols.
For us, any set qualifies as a possible alphabet, so long as it is finite.
Examples:
∑1 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} — 10-element set of decimal digits.
∑2 = {a, b, c, . . . , x, y, z} — 26-element set of lower-case characters of the English
language.
Non-example:
N = {0, 1, 2, 3, . . . } — set of all non-negative whole numbers is not an alphabet,
because it is infinite.
STRINGS OVER AN ALPHABET
∑* set of all strings over ∑ of any finite length

Kleene Star (*)

If Σ is an alphabet (a set of symbols), then the Kleene star of Σ , denoted Σ∗ , is the set
of all strings of finite length consisting of symbols in Σ , including the empty string λ
REGULAR EXPRESSIONS
• An expression is regular if:
• ɸ is a regular expression for regular language ɸ.
• ɛ is a regular expression for regular language {ɛ}.
• If a ∈ Σ (Σ represents the input alphabet), a is regular expression with language
{a}.
• If a and b are regular expression, a + b is also a regular expression with
language {a,b}.
• If a and b are regular expression, ab (concatenation of a and b) is also regular.
• If a is regular expression, a* (0 or more times a) is also regular.
REGULAR EXPRESSIONS
Example 1:
Language L of words defined over ∑= {a,b) starting with a
∑= {a,b)
∑={ a,ab, abb, abbb,abbba,abbbb, aa,aaa, ……….}
RE= (ab*)
“All words of the string form one “A” followed by some numbers of b‟s (may be
no b at all)
REGULAR EXPRESSIONS
Example 2:
Language L of words defined over ∑= {a,b) starting with “a”, following some b and
ends with “a”
∑= {a,b)
∑={ a,aba, abba, abbba,abbba,abbbba, aa,aaba, ……….}
RE= (ab*a)
“All words of the string form one “A” followed by some numbers of b‟s (may be
no b at all) and ends with a
REGULAR EXPRESSIONS
Example 2:
Language L of words defined over ∑= {a,b,c) starting with “a” or “c” then followed
some “b”.
∑= {a,b,c)
∑={ a,c, ab, cb,abb, cbb, abbbb, cbbb, ……….}
RE= ((a+c)b*)
“All words of the string form one “a” OR “c” followed by some numbers of b‟s
(may be no b at all)
REGULAR EXPRESSION
REGULAR LANGUAGES

Regular Expression Regular Languages

set of vovels (a∪e∪i∪o∪u) {a, e, i, o, u}

a followed by 0 or more b (a.b*) {a, ab, abb, abbb, abbbb,….}

{ ε , a ,aou, aiou, b, abcd…..}


any no. of vowels followed by v*.c* ( where v – vowels and c – where ε represent empty string
any no. of consonants consonants) (in case 0 vowels and o
consonants )
LANGUAGES
A (formal) language “L” over an alphabet Σ is just a set of strings in Σ *.
FINITE AUTOMATA/FINITE STATE MACHINES
It is conventional to draw finite automata as a graph where the
states are drawn as circles and the accept/output states are drawn
as double circles.
Example, an automaton that accepts the same strings as the regular
expression ab* is shown

Language starting with Letter ―a‖


followed by any number of ―b‖
SIMPLE FINITE STATE MACHINES
Example 1 − For a regular expression „a‟, we Example 3 − For a regular expression (a+b), we
can construct the following FA − can construct the following FA −

Example 2 − For a regular expression (a+b), we Example 3 − For a regular expression (a+b)*, we
can construct the following FA − can construct the following FA −

You might also like