1 PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 58

Introduction Formal Denitions and Notation

Example DFA 1
DFA for Odd number of as
b
a
b
a
How a DFA works.
Introduction Formal Denitions and Notation
Example DFA 1
DFA for Odd number of as
b
a
b
a
e o
How a DFA works.
Each state represents a property of the input string read so
far:
State e: Number of as seen is even.
State o: Number of as seen is odd.
Introduction Formal Denitions and Notation
Example DFA 2
DFA for Contains the substring abb
a b b
a
a b a, b
Each state represents a property of the input string read so far:
Introduction Formal Denitions and Notation
Example DFA 2
DFA for Contains the substring abb
a
a b b
a
a b a, b
ab abb
Each state represents a property of the input string read so far:
State : Not seen abb and no sux in a or ab.
State a: Not seen abb and has sux a.
State ab: Not seen abb and has sux ab.
State abb: Seen abb.
Introduction Formal Denitions and Notation
Example DFA 3
Accept strings over {0, 1} which satisfy even parity in length 4
blocks.
Accept 0101 1010
Reject 0101 1011
DFA for Even parity checker
0
1
0, e
0 0
0
0 0
1
1
1
1
1
0
0, 1
1
1, o
1, e
2, o 3, o
0, o
2, e 3, e
Introduction Formal Denitions and Notation
Example DFA 4
Accept strings over {a, b, /, } which dont end inside a C-style
comment.
Scan from left to right till rst /* is encountered; from
there to next */ is rst comment; and so on.
Accept ab/ aaa /abba and ab/ aa/ aa /bb /.
Reject ab/ aaa and ab/ aa/ aa /bb/ a.
Introduction Formal Denitions and Notation
Example DFA 4
Accept strings over {a, b, /, } which dont end inside a C-style
comment.
Scan from left to right till rst /* is encountered; from
there to next */ is rst comment; and so on.
Accept ab/ aaa /abba and ab/ aa/ aa /bb /.
Reject ab/ aaa and ab/ aa/ aa /bb/ a.
DFA for C-comment tracker
pbc
/
/ a,
in pec out
a
a, /
/

a
Introduction Formal Denitions and Notation
Denitions and notation
An alphabet is nite set of set of symbols or letters. Eg.
A = {a, b, c}, = {0, 1}.
A string or word over an alphabet A is a nite sequence of
letters from A. Eg. aaba is string over {a, b, c}.
Empty string denoted by .
Set of all strings over A denoted by A

.
What is the size or cardinality of A

?
Introduction Formal Denitions and Notation
Denitions and notation
An alphabet is nite set of set of symbols or letters. Eg.
A = {a, b, c}, = {0, 1}.
A string or word over an alphabet A is a nite sequence of
letters from A. Eg. aaba is string over {a, b, c}.
Empty string denoted by .
Set of all strings over A denoted by A

.
What is the size or cardinality of A

?
Innite but Countable: Can enumerate in lexicographic order:
, a, b, c, aa, ab, . . .
.
Introduction Formal Denitions and Notation
Denitions and notation
An alphabet is nite set of set of symbols or letters. Eg.
A = {a, b, c}, = {0, 1}.
A string or word over an alphabet A is a nite sequence of
letters from A. Eg. aaba is string over {a, b, c}.
Empty string denoted by .
Set of all strings over A denoted by A

.
What is the size or cardinality of A

?
Innite but Countable: Can enumerate in lexicographic order:
, a, b, c, aa, ab, . . .
.
Operation of concatenation on words: String u followed by
string v: written u v or simply uv.
Eg. aabb aaa = aabbaaa.
Introduction Formal Denitions and Notation
Denitions and notation: Languages
A language over an alphabet A is a set of strings over A. Eg.
for A = {a, b, c}:
L = {abc, aaba}.
L
1
= {, b, aa, bb, aab, aba, baa, bbb, . . .}.
L
2
= {}.
L
3
= {}.
How many languages are there over a given alphabet A?
Introduction Formal Denitions and Notation
Denitions and notation: Languages
A language over an alphabet A is a set of strings over A. Eg.
for A = {a, b, c}:
L = {abc, aaba}.
L
1
= {, b, aa, bb, aab, aba, baa, bbb, . . .}.
L
2
= {}.
L
3
= {}.
How many languages are there over a given alphabet A?
Uncountably innite
Introduction Formal Denitions and Notation
Denitions and notation: Languages
A language over an alphabet A is a set of strings over A. Eg.
for A = {a, b, c}:
L = {abc, aaba}.
L
1
= {, b, aa, bb, aab, aba, baa, bbb, . . .}.
L
2
= {}.
L
3
= {}.
How many languages are there over a given alphabet A?
Uncountably innite
Concatenation of languages:
L
1
L
2
= {u v | u L
1
, v L
2
}.
Eg. {abc, aaba} {, a, bb} =
{abc, aaba, abca, aabaa, abcbb, aababb}.
Introduction
Denitions and notation: DFA
A Deterministic Finite Automaton A is a 5-tuple (Q, A, s, , F)
where
Q is a nite set of states,
A is the input alphabet,
s Q is the start state (or initial state),
: Q A Q is the transition function, and
F Q is the set of nal states (or accepting states).
Introduction Formal Denitions and Notation
Denitions and notation: Language accepted by a DFA

tells us how the DFA A behaves on a given word u.


Dene

: Q A

Q as

(q, ) = q

(q, w a) = (

(q, w), a).


Language accepted by A, denoted L(A), is dened as:
L(A) = {w A

|

(s, w) F}.
Eg. For A = DFA for Odd as,
L(A) = {a, ab, ba, aaa, abb, bab, bba, . . .}.
Introduction Formal Denitions and Notation
Regular Languages
A language L A

is called regular if there is a DFA A over


A such that L(A) = L.
Examples of regular languages: Odd as, strings that dont
end inside a C-style comment, {}, any nite language.
All languages over A
Regular
Are there non-regular languages?
Introduction Formal Denitions and Notation
Regular Languages
A language L A

is called regular if there is a DFA A over


A such that L(A) = L.
Examples of regular languages: Odd as, strings that dont
end inside a C-style comment, {}, any nite language.
All languages over A
Regular
Are there non-regular languages?
Yes, uncountably many, since Reg is only countable while class
of all languages is uncountable.
Closure under boolean ops Induction NFAs
Closure properties
Class of Regular languages is closed under
Complement, intersection, and union.
Concatenation, Kleene iteration.
Non-deterministic Finite-state Automata (NFA) = DFA.
All strings over A
L M
All languages over A
Regular
Closure under boolean ops Induction NFAs
Closure under complementation
Idea: Flip nal states.
Formal construction:
Let A = (Q, s, , F) be a DFA over alpahet A.
Dene B = (Q, s, , Q F).
Claim: L(B) = A

L(A).
Proof of claim
L(B) A

L(A).
w L(B) =

(s, w) (Q F).
=

(s, w) F
= w L(A)
= w A

L(A).
L(B) A

L(A).
Closure under boolean ops Induction NFAs
Closure under intersection
Product construction. Given DFAs A = (Q, s, , F),
B = (Q

, s

, F

), dene product C of A and B:


C = (Q Q

, (s, s

),

, F F

),
where

((p, p

), a) = ((p, a),

(p

, a)).
Product construction example
b
a
b
a
e o
a
b
b
a
b b
b
b
a
a
b
a a
e, b o, b
o, b
e, b
b
A B AB
Closure under boolean ops Induction NFAs
Correctness of product construction
Claim: L(C) = L(A) L(B).
Proof of claim L(C) = L(A) L(B).
L(C) L(A) L(B).
w L(C) =

((s, s

), w) F F

.
= (

(s, w),

(s

, w)) F F

(by subclaim)
=

(s, w) F and

(s

, w) F

= w L(A) and w L(B)


= w L(A) L(B).
L(C) L(A) L(B).
Subclaim:

((s, s

), w) = (

(s, w),

(s

, w)).
Closure under boolean ops Induction NFAs
Closure under union
Follows from closure under complement and intersection since
L
1
L
2
= L
1
L
2
.
Closure under boolean ops Induction NFAs
Closure under union
Follows from closure under complement and intersection since
L
1
L
2
= L
1
L
2
.
Can also do directly by product construction: Given DFAs
A = (Q, s, , F), B = (Q

, s

, F

), dene C:
C = (Q Q

, (s, s

),

, (F Q

) (Q F

)), where

((p, p

), a) = ((p, a), (p

, a)).
Union construction
b
a
b
a
e o
a
b
b
a
b b
b
b
a
a
b
a a
e, b o, b
o, b
e, b
b
A B AB
Closure under boolean ops Induction NFAs
Principle of Mathematical Induction
N = {0, 1, 2 . . .}
P(n): A statement P about a natural number n.
Example:
P(n) = n is even.
P
1
(n) = Sum of the numbers 1 . . . n equals n(n + 1)/2.
P
2
(n) = For all w A

, if length of w is n then

((s, s

), w) = (

(s, w),

(s

, w)).
Principle of Induction
If a statement P about natural numbers
is true for 0 (i.e P(0) is true), and,
is true for n + 1 whenever it is true for n (i.e.
P(n) = P(n + 1))
then P is true of all natural numbers (i.e. For all n, P(n) is
true).
Closure under boolean ops Induction NFAs
Proof of subclaim
Exercise: Prove the Subclaim:

((s, s

), w) = (

(s, w),

(s

, w)).
using induction.
Closure under boolean ops Induction NFAs
Nondeterministic Finite-state Automata (NFA)
Allows multiple start states.
Allows more than one transition from a state on a given letter.
Non-deterministic transitions
a
a
p
q
r
A word is accepted if there is some path on it from a start to
a nal state.
Closure under boolean ops Induction NFAs
Example NFAs
NFA for contains abb as a subword
a
a b
a, b
ab abb
b
a, b
NFAs
NFA denition
A nondeterministic nite automaton (NFA) A is a 5-tuple
(Q, A, s, , F), where
Q is a nite set of states,
A is the input alphabet,
s Q is the start state (or initial state),
: Q A 2
Q
is the transition relation, and
F Q is the set of nal states (or accepting states).
Closure under boolean ops Induction NFAs
Closure under concatenation and Kleene iteration
Concatenation of languages:
L M = {u v | u L, v M}.
Kleene iteration of a language:
L

= {} L L
2
L
3
,
where
L
n
= L L L(n times).
= {w
1
w
n
| each w
i
L}.
Regular Expressions Kleenes Theorem Equation-based alternate construction
Examples of Regular Expressions
Expressions built from a, b, , using operators +, , and .
(a

+ b

) c
Strings of only as or only bs, followed by a c.
(a + b)

abb(a + b)

contains abb as a subword.


(a + b)

b(a + b)(a + b)
3rd last letter is a b.
(b

ab

a)

Regular Expressions Kleenes Theorem Equation-based alternate construction


Examples of Regular Expressions
Expressions built from a, b, , using operators +, , and .
(a

+ b

) c
Strings of only as or only bs, followed by a c.
(a + b)

abb(a + b)

contains abb as a subword.


(a + b)

b(a + b)(a + b)
3rd last letter is a b.
(b

ab

a)

Even number of as.


Regular Expressions Kleenes Theorem Equation-based alternate construction
Examples of Regular Expressions
Expressions built from a, b, , using operators +, , and .
(a

+ b

) c
Strings of only as or only bs, followed by a c.
(a + b)

abb(a + b)

contains abb as a subword.


(a + b)

b(a + b)(a + b)
3rd last letter is a b.
(b

ab

a)

Even number of as.


Ex. Give regexp for Every 4-bit block of the form
w[4i , 4i + 1, 4i + 2, 4i + 3] has even parity.
Regular Expressions Kleenes Theorem Equation-based alternate construction
Examples of Regular Expressions
Expressions built from a, b, , using operators +, , and .
(a

+ b

) c
Strings of only as or only bs, followed by a c.
(a + b)

abb(a + b)

contains abb as a subword.


(a + b)

b(a + b)(a + b)
3rd last letter is a b.
(b

ab

a)

Even number of as.


Ex. Give regexp for Every 4-bit block of the form
w[4i , 4i + 1, 4i + 2, 4i + 3] has even parity.
(0000 + 0011 + + 1111)

( + 0 + 1 + + 111)
Regular Expressions Kleenes Theorem Equation-based alternate construction
Formal denitions
Syntax of regular expresions over an alphabet A:
r ::= | a | r + r | r r | r

where a A.
Semantics: associate a language L(r ) A

with regexp r .
L() = {}
L(a) = {a}
L(r + r

) = L(r ) L(r

)
L(r r

) = L(r ) L(r

)
L(r

) = L(r )

.
Regular Expressions Kleenes Theorem Equation-based alternate construction
Formal denitions
Syntax of regular expresions over an alphabet A:
r ::= | a | r + r | r r | r

where a A.
Semantics: associate a language L(r ) A

with regexp r .
L() = {}
L(a) = {a}
L(r + r

) = L(r ) L(r

)
L(r r

) = L(r ) L(r

)
L(r

) = L(r )

.
Question: Do we need in syntax?
Regular Expressions Kleenes Theorem Equation-based alternate construction
Formal denitions
Syntax of regular expresions over an alphabet A:
r ::= | a | r + r | r r | r

where a A.
Semantics: associate a language L(r ) A

with regexp r .
L() = {}
L(a) = {a}
L(r + r

) = L(r ) L(r

)
L(r r

) = L(r ) L(r

)
L(r

) = L(r )

.
Question: Do we need in syntax?
No.

.
Regular Expressions Kleenes Theorem Equation-based alternate construction
Example: Semantics of regexp
(a

+ b

) c

a b c
Regular Expressions Kleenes Theorem Equation-based alternate construction
Example: Semantics of regexp
(a

+ b

) c

a b {a} {b} c {c}


Regular Expressions Kleenes Theorem Equation-based alternate construction
Example: Semantics of regexp
(a

+ b

) c

a b {a} {b} c {c}


{, a, aa, . . .} {, b, bb, . . .}
Regular Expressions Kleenes Theorem Equation-based alternate construction
Example: Semantics of regexp
(a

+ b

) c

+ {, a, b, aa, bb, . . .}

a b {a} {b} c {c}


{, a, aa, . . .} {, b, bb, . . .}
Regular Expressions Kleenes Theorem Equation-based alternate construction
Example: Semantics of regexp
(a

+ b

) c

+ {, a, b, aa, bb, . . .}

a b {a} {b} c {c}


{, a, aa, . . .} {, b, bb, . . .}
{c, ac, bc, aac, bbc, . . .}
Regular Expressions Kleenes Theorem Equation-based alternate construction
Kleenes Theorem: RE = DFA
Class of languages dened by regular expressions coincides with
regular languages.
Proof
RE DFA: Use closure properties of regular languages.
DFA RE:
Regular Expressions Kleenes Theorem Equation-based alternate construction
DFA RE: Kleenes construction
Let A = (Q, s, , F) be given DFA.
Dene L
pq
= {w A

|

(p, w) = q}.
Then L(A) =

f F
L
sf
.
For X Q, dene L
X
pq
= {w A

|

(p, w) =
q via a path that stays in X except for rst and last states}
X
p q
Then L(A) =

f F
L
Q
sf
.
Regular Expressions Kleenes Theorem Equation-based alternate construction
DFA RE: Kleenes construction
p q
r
X
Advantage:
L
X{r}
pq
= L
X
pq
+ L
X
pr
(L
X
rr
)

L
X
rq
.
Regular Expressions Kleenes Theorem Equation-based alternate construction
DFA RE: Kleenes construction (2)
Method:
Begin with L
Q
sf
for each f F.
Simplify by using terms with strictly smaller Xs:
L
X{r}
pq
= L
X
pq
+ L
X
pr
(L
X
rr
)

L
X
rq
.
For base terms, observe that
L
{}
pq
=

{a | (p, a) = q} if p = q
{a | (p, a) = q} {} if p = q.
Exercise: convert NFA/DFAs below to REs:
s
b
a, b
f
b
a
b
a
Regular Expressions Kleenes Theorem Equation-based alternate construction
DFA RE: Kleenes construction (2)
Method:
Begin with L
Q
sf
for each f F.
Simplify by using terms with strictly smaller Xs:
L
X{r}
pq
= L
X
pq
+ L
X
pr
(L
X
rr
)

L
X
rq
.
For base terms, observe that
L
{}
pq
=

{a | (p, a) = q} if p = q
{a | (p, a) = q} {} if p = q.
Exercise: convert NFA/DFAs below to REs:
s
b
a, b
f
b
a
b
a
e o
Regular Expressions Kleenes Theorem Equation-based alternate construction
DFA RE using system of equations
Aim: to construct a regexp for
L
q
= {w A

|

(q, w) F}.
Note that L(A) = L
s
.
Example:
b
a
b
a
Set up equations to capture L
q
s:
x
e
= b x
e
+ a x
o
x
o
= a x
e
+ b x
o
+ .
Solution is a RE for each x, such that languages denoted by
LHS and RHS REs coincide.
Regular Expressions Kleenes Theorem Equation-based alternate construction
DFA RE using system of equations
Aim: to construct a regexp for
L
q
= {w A

|

(q, w) F}.
Note that L(A) = L
s
.
Example:
b
a
b
a
e o
Set up equations to capture L
q
s:
x
e
= b x
e
+ a x
o
x
o
= a x
e
+ b x
o
+ .
Solution is a RE for each x, such that languages denoted by
LHS and RHS REs coincide.
Regular Expressions Kleenes Theorem Equation-based alternate construction
Solving a system of equations
L
q
s are a solution to the system of equations
In general there could be many solutions to equations.
Consider x = A

x.
In this case, L
q
s can be seen to the least solution to the
equations.
Regular Expressions Kleenes Theorem Equation-based alternate construction
Least solution to the system of equations
Equations can be viewed as:
[ x
e
x
o
] =

b a
a b

[
x
e
x
o
] + [ ]
System of equations have the general form:
X = AX
T
+ B.
Claim: A

B is the least solution to the equations above. [See


Kozen, Supplementary Lecture A].
Denition of A

a b
c d

(a + bd

c)

(a + bd

c)

bd

(d + ca

b)

ca

(d + ca

b)

Homomorphism from

to

A map
h :

satisfying:
1
h() = .
2
h(u v) = h(u) h(v).
u v
u v
h(u)
h(v)
h(u) h(v) h

Examples
h : {a, b}

{a}

given by h(w) = a
#
a
(w)
.
So h(aabbabb) = aaa.
Examples
h : {a, b}

{a}

given by h(w) = a
#
a
(w)
.
So h(aabbabb) = aaa.
Some observations:
First clause in denition of homomorphism is redundant
Examples
h : {a, b}

{a}

given by h(w) = a
#
a
(w)
.
So h(aabbabb) = aaa.
Some observations:
First clause in denition of homomorphism is redundant
h( ) = h() h()
That is h() = h() h().
Only can satisfy this equation.
Examples
h : {a, b}

{a}

given by h(w) = a
#
a
(w)
.
So h(aabbabb) = aaa.
Some observations:
First clause in denition of homomorphism is redundant
h( ) = h() h()
That is h() = h() h().
Only can satisfy this equation.
h is determined completely by h on .
For example above: h is determined by
a a
b .
Homomorphisms preserve regular sets
Let h :

be a homomorphism. Then
Fact 1
If L

is regular, then so is h(L).


h

L
h(L)
Homomorphisms preserve regular sets
Dene h
1
:

by h
(
w) = {u

| h(u) = w}.
Dene h
1
(M) =

wM
h
1
(w).
Fact 2
If M

is regular, then so is h
1
(M).
h

h
1
(M)
M
Some applications: NFAs with -transitions
NFA with -labelled transitions:
: Q (A {}) 2
Q
.
Accepts a word w if there is a path from a start state to a
nal state labelled by a word u such that h(u) = w, where
a a
.
Claim: NFAs with -transitions accept only regular sets.
Observe that L(A) = h(L(A

)), where A

is A viewed as
running over the alphabet A {}.

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