Chapter 1 To 10
Chapter 1 To 10
Chapter 1
Computing Is About Boolean Logic
NOT
P
True
False
Boolean Operators
NOT
P
True False
False True
Boolean Operators
AND
P Q PQ
True True
True False
False True
False False
Boolean Operators
AND
P Q PQ
True True True
True False False
False True False
False False False
Boolean Operators
OR
P Q PQ
True True
True False
False True
False False
Boolean Operators
OR
P Q PQ
True True True
True False True
False True True
False False False
Boolean Operators
IMPLIES
P Q PQ
True True
True False
False True
False False
Boolean Operators
IMPLIES
P Q PQ
True True True
True False False
False True True
False False True
Boolean Operators
EQUIVALENCE
P Q PQ
True True
True False
False True
False False
Boolean Operators
EQUIVALENCE
P Q PQ
True True True
True False False
False True False
False False True
Boolean Logic
P Q P
True True
True False
False True
False False
P ((P Q) Q)
Using Boolean Logic
P Q P PQ
True True False
P ((P Q) Q)
Using Boolean Logic
P Q P P Q (P Q) Q
True True False True
P ((P Q) Q)
Using Boolean Logic
P Q P P Q (P Q) Q
True True False True True
P ((P Q) Q)
Using Boolean Logic
P ((P Q) Q)
Using Boolean Logic
P ((P Q) Q)
Another Example
E H N S EH ((E H) N S
Another Example
E H N S EH ((E H) N S
Let’s practice.
Boolean Identities
This notation:
• Multiply for AND
• Add for OR
Proving These Things
Prove the first of deMorgan’s laws:
(A B) A B
A B AB (A B)
True True True False
True False False True
False True False True
False False False True
A B A B A B
True True False False False
True False False True True
False True True False True
False False True True True
Proving These Things
Prove the first of deMorgan’s laws:
(A B) A B
A B AB (A B)
True True True False
True False False True
False True False True
False False False True
A B A B A B
True True False False False
True False False True True
False True True False True
False False True True True
Satisfiability
(W C D) (W A D)
P Q
T T T T T T T T T T F F F F F F F F
T F T T T T F F F F T T T T F F F F
F T T T F F T T F F T T F F T T F F
F F T F T F T F T F T F T F T F T F
Exclusive Or XOR
P Q PQ
True True
True False
False True
False False
Chips OR Fries
Boolean Operators
Exclusive Or XOR
P Q PQ
True True False
True False True
False True True
False False False
Chips OR Fries
Boolean Operators
P Q NAND
True True True
True False False
False True False
False False False
Boolean Operators
P Q NAND
True True True False
True False False True
False True False True
False False False True
Boolean Operators
Not Or NOR
P Q NOR
True True True
True False True
False True True
False False False
Boolean Operators
Not Or NOR
P Q NOR
True True True False
True False True False
False True True False
False False False True
Binary Boolean Operators
NA NOR
P Q ND
T T T T T T T T T T F F F F F F F F
T F T T T T F F F F T T T T F F F F
F T T T F F T T F F T T F F T T F F
F F T F T F T F T F T F T F T F T F
Satisfiability
L3 69
Tautologies and contradictions
The easiest way to see if a compound
proposition is a tautology/contradiction is
to use a truth table.
p p p p p p p p
F T T F T F
T F T T F F
L3 70
Tautology example (1.2.8.a)
Part 1
Demonstrate that
[¬p (p q )]q
is a tautology in two ways:
1. Using a truth table – show that [¬p
(p q )]q is always true
2. Using a proof (will get to this later).
L3 71
Tautology by truth table
T F
F T
F F
L3 72
Tautology by truth table
T F F
F T T
F F T
L3 73
Tautology by truth table
T F F T
F T T T
F F T F
L3 74
Tautology by truth table
T F F T F
F T T T T
F F T F F
L3 75
Tautology by truth table
T F F T F T
F T T T T T
F F T F F T
L3 76
Logical Equivalence of Conditional
and Contrapositive
The easiest way to check for logical
equivalence is to see if the truth tables of both
variants have identical last columns:
p q p q p q ¬q ¬p ¬q¬p
p q p q p q ¬q ¬p ¬q¬p
T T T
T F F
F T T
F F T
p q p q p q ¬q ¬p ¬q¬p
T T T T T
T F F T F
F T T F T
F F T F F
p q p q p q ¬q ¬p ¬q¬p
T T T T T F
T F F T F T
F T T F T F
F F T F F T
p q p q p q ¬q ¬p ¬q¬p
T T T T T F F
T F F T F T F
F T T F T F T
F F T F F T T
p q p q p q ¬q ¬p ¬q¬p
T T T T T F F T
T F F T F T F F
F T T F T F T T
F F T F F T T T
L3 83
Logical Non-Equivalence of
Conditional and Converse
The converse of a logical implication is the reversal of the
implication. I.e. the converse of p q is q p.
EG: The converse of “If Donald is a duck then Donald is a bird.” is
“If Donald is a bird then Donald is a duck.”
As we’ll see next: p q and q p are not logically equivalent.
L3 84
Logical Non-Equivalence of
Conditional and Converse
p q p q q p (p q) (q p)
L3 85
Logical Non-Equivalence of
Conditional and Converse
p q p q q p (p q) (q p)
T T
T F
F T
F F
L3 86
Logical Non-Equivalence of
Conditional and Converse
p q p q q p (p q) (q p)
T T T
T F F
F T T
F F T
L3 87
Logical Non-Equivalence of
Conditional and Converse
p q p q q p (p q) (q p)
T T T T
T F F T
F T T F
F F T T
L3 88
Logical Non-Equivalence of
Conditional and Converse
p q p q q p (p q) (q p)
T T T T T
T F F T F
F T T F F
F F T T T
L3 89
Derivational Proof Techniques
When compound propositions involve more and
more atomic components, the size of the truth
table for the compound propositions increases
Q1: How many rows are required to construct the
truth-table of:
( (q(pr )) ((sr)t) ) (qr )
Q2: How many rows are required to construct the
truth-table of a proposition involving n atomic
components?
L3 90
Derivational Proof Techniques
A1: 32 rows, each additional variable doubles the
number of rows
A2: In general, 2n rows
Therefore, as compound propositions grow in
complexity, truth tables become more and more
unwieldy. Checking for tautologies/logical
equivalences of complex propositions can
become a chore, especially if the problem is
obvious.
L3 91
Derivational Proof Techniques
EG: consider the compound proposition
(p p ) ((sr)t) ) (qr )
L3 92
Derivational Proof Techniques
A: Part of it is a tautology (p p ) and the
disjunction of True with any other
compound proposition is still True:
(p p ) ((sr)t )) (qr )
T ((sr)t )) (qr )
T
Derivational techniques formalize the
intuition of this example.
L3 93
Tables of Logical Equivalences
• Identity laws
Like adding 0
• Domination laws
Like multiplying by 0
• Idempotent laws
Delete redundancies
• Double negation
“I don’t like you, not”
• Commutativity
Like “x+y = y+x”
• Associativity
Like “(x+y)+z = y+(x+z)”
• Distributivity
Like “(x+y)z = xz+yz”
L3 94
• De Morgan
Tables of Logical Equivalences
• Excluded middle
• Negating creates opposite
• Definition of implication in
terms of Not and Or
L3 95
DeMorgan Identities
DeMorgan’s identities allow for simplification of
negations of complex expressions
• Conjunctional negation:
(p1p2…pn) (p1p2…pn)
“It’s not the case that all are true iff one is false.”
• Disjunctional negation:
(p1p2…pn) (p1p2…pn)
“It’s not the case that one is true iff all are false.”
L3 96
Tautology example (1.2.8.a) Part 2
Demonstrate that
[¬p (p q )]q
is a tautology in two ways:
1. Using a truth table (did above)
2. Using a proof relying on Tables 5 and 6
of Rosen, section 1.2 to derive True
through a series of logical equivalences
L3 97
Tautology by proof
[¬p (p q )]q
L3 98
Tautology by proof
[¬p (p q )]q
[(¬p p)(¬p q)]q Distributive
L3 99
Tautology by proof
[¬p (p q )]q
[(¬p p)(¬p q)]q Distributive
[ F (¬p q)]q ULE
L3 100
Tautology by proof
[¬p (p q )]q
[(¬p p)(¬p q)]q Distributive
[ F (¬p q)]q ULE
[¬p q ]q Identity
L3 101
Tautology by proof
[¬p (p q )]q
[(¬p p)(¬p q)]q Distributive
[ F (¬p q)]q ULE
[¬p q ]q Identity
¬ [¬p q ] q ULE
L3 102
Tautology by proof
[¬p (p q )]q
[(¬p p)(¬p q)]q Distributive
[ F (¬p q)]q ULE
[¬p q ]q Identity
¬ [¬p q ] q ULE
[¬(¬p) ¬q ] q DeMorgan
L3 103
Tautology by proof
[¬p (p q )]q
[(¬p p)(¬p q)]q Distributive
[ F (¬p q)]q ULE
[¬p q ]q Identity
¬ [¬p q ] q ULE
[¬(¬p) ¬q ] q DeMorgan
[p ¬q ] q Double Negation
L3 104
Tautology by proof
[¬p (p q )]q
[(¬p p)(¬p q)]q Distributive
[ F (¬p q)]q ULE
[¬p q ]q Identity
¬ [¬p q ] q ULE
[¬(¬p) ¬q ] q DeMorgan
[p ¬q ] q Double Negation
p [¬q q ] Associative
L3 105
Tautology by proof
[¬p (p q )]q
[(¬p p)(¬p q)]q Distributive
[ F (¬p q)]q ULE
[¬p q ]q Identity
¬ [¬p q ] q ULE
[¬(¬p) ¬q ] q DeMorgan
[p ¬q ] q Double Negation
p [¬q q ] Associative
p [q ¬q ] Commutative
L3 106
Tautology by proof
[¬p (p q )]q
[(¬p p)(¬p q)]q Distributive
[ F (¬p q)]q ULE
[¬p q ]q Identity
¬ [¬p q ] q ULE
[¬(¬p) ¬q ] q DeMorgan
[p ¬q ] q Double Negation
p [¬q q ] Associative
p [q ¬q ] Commutative
pT ULE
L3 107
Tautology by proof
[¬p (p q )]q
[(¬p p)(¬p q)]q Distributive
[ F (¬p q)]q ULE
[¬p q ]q Identity
¬ [¬p q ] q ULE
[¬(¬p) ¬q ] q DeMorgan
[p ¬q ] q Double Negation
p [¬q q ] Associative
p [q ¬q ] Commutative
pT ULE
T Domination
L3 108
CSC211
Discrete Me t h o d s
Lecture 1
Languages and Grammars
Fall 2016
CSC211 - DISCRETE METHODS Spring 2015
1.0 O UTLINE 2
CSC211 - DISCRETE METHODS Spring 2015
< sentence>
→ < noun phrase> < verb phrase>
→ < article> < noun> < verb phrase>
→ < article> < noun> < verb> < adverb>
→ < t he> < noun> < verb> < adverb>
→ < t he> < cat > < verb> < adverb>
→ < t he> < cat > < walks> < adverb>
→ < t he> < cat > < walks> < quickly>
Exercise 1.1. Form all ot her valid sent ences generat ed by t his grammar.
2. Formal Languages
• A formal language is a set of finite-lengt h words (or “st rings”)
over some finit e alphabet
• A typical alphabet would be { a, b} , a typical st ring over t hat
alphabet would be ababba, and a typical language over t hat
alphabet cont aining t hat st ring would be t he set of all st rings
which cont ain t he same number of a’s as b’s.
• T he empty word is allowed and is usually denot ed by λ .
• Not e t hat while t he alphabet is a finit e set and every st ring has
finit e lengt h, a language may cont ain an infinit e number of st rings.
Definition 1.1.
• An alphabet (or vocabulary) V is a finit e, non-empty set of
element s called symbols
• A st ring (or word) over an alphabet V is a concat enat ion of a
finit e number of element s of V
• T he empty st ring or null st ring, denot ed by λ , is t he st ring
cont aining no symbols (not e t hat { λ } =I ∅)
• T he set of all words over an alphabet V is denot ed by V ∗
• A language over an alphabet V is a subset of V ∗
Languages can be specified in various ways –
(1) List all t he words in t he language: L = { 0, 00, 000, 0000, 00000} .
(2) Give some crit eria t hat a word must sat isfy: L = { 0n |n ∈ N} .
(3) Using a formal grammar.
• P hrase st ruct ure grammars are also called unrest rict ed grammars.
• T he element s of V \ T are called non-t erminal symbols.
• Every product ion in P must cont ain at least one non-t erminal
symbol on it s left side.
• A derivat ion is a sequence of rule applicat ions, st art ing wit h S.
• T he t erminal symbols T correspond t o t he alphabet of t he
associat ed formal language.
above example.
w0 ⇒ w1 , w1 ⇒ w2 , . . . , wn− 1 ⇒ wn (n ≥ 0)
L(G) = { w ∈ T ∗ : S∗ ⇒ w}
Example 1.7. Find two phrase st ruct ure grammars t hat generat e t he
language L = { 0m 1n : m, n ≥ 0}
Solut ion:
One answer is G1 = { V, T, S, P} where
V = { S, 0, 1}
T = { 0, 1}
P = { S → 0S, S → S1, S → λ }
T he st ring 0m 1n is obt ained by applying t he first product ion m t imes and
t he second product ion n t imes.
2.0 O UTLINE 2
CSC211 - DISCRETE METHOD SPRING 2015
Definition 2.1.
(1) A formal grammar G = (V, T, S, P) is cont ext -sensit ive or Type-1
if all product ion rules in P are of t he form x → y where x and y
are any two st rings over V such t hat |x| ≤ |y|.
(2) A formal language is cont ext -sensitive if t here is a
cont ext -sensit ive grammar which generat es it .
• T he t erm cont ext -free derives from t he fact t hat A can always be
replaced by x, regardless of cont ext in which it occurs.
• Cont ext -free languages are t he t heoret ical basis for t he synt ax of
most programming languages.
Definition 2.4.
(1) If G is eit her right or left linear, t hen G is called a regular or
Type-3 grammar.
( 2 ) T he language L(G) generat ed by a regular grammar G is called a
regular language.
Regular Languages
3.0 O UTLINE 2
CSCS211 D ISCRETE M ATHEMATICS II SPRING 2015
Not e t hat L 1 L 2 /=
L 2L 1.
3.1 K LEENE CLOSURE 3
CSC211 - DISCRETE METHOD SPRING 2015
Not e t hat L 1 L 2 /=
L 2L 1.
3.1 K LEENE CLOSURE 3
CSC211 - DISCRETE METHOD SPRING 2015
/ L 2L 1.
Not e t hat L 1 L 2 =
L0 = { λ } and L n+ 1 = for n = 1, 2, . . .
L nL
𝐿𝐿∗ = � 𝐿𝐿𝑛𝑛
𝑛𝑛=0
2. Regular languages
A regular language L sat isfies t he following equivalent propert ies:
• L can be generat ed by a regular grammar.
• L can be described by a regular expression.
• L can be accept ed by a finit e st at e machine.
• L can be accept ed by a read-only Turing machine.
Example 3.3.
Regular expression Descript ion
a∗ a repeat ed any number of t imes
a∗b∗ Any number of as followed by any number of bs
(abc)d ∗(ca) ∗ abc followed by d any number of t imes fol-
lowed by ca any number of t imes
(a ∪b) ∗(aa) ∗ Any st ring consist ing of as or bs followed by
any even number of as
5.0 O UTLINE 2
CSC211 - DISCRETE METHOD SPRING 2015
Definition 5.1. A finit e-st ate aut omat on or finit e-state machine
M = (S, I, f , s0 , F ; O, g) consist s of
(1) A finit e set of st at es S ,
(2) A finit e input alphabet I,
(3) A t ransit ion funct ion f : S × I → S which assigns a new st at e t o
(st at e, input ) pairs,
(4) An init ial st at e s0 ∈S ,
(5) A set of final st at es F ⊂ S ,
(6) A finit e out put alphabet O,
(7) An out put funct ion g : S × I → O which assigns an out put t o
(st at e, input ) pairs.
Not e t hat f and g are part ial funct ions – t hey need not be defined for
s1
st art s0 s3
s2
s1
(10, )
st art s0 s3
(20, )
s2
s1
(R, ) (10, )
st art s0 s3
(B , ) (20, )
s2
s1
(R, ) (10, )
st art s0 s3
(10, )
(B , ) (20, )
s2
s1
(R, ) (10, )
(20, )
st art s0 s3
(10, )
(B , ) (10, )
(20, )
s2 (20, 10)
(R, )
(B , )
s1
(R, ) (10, )
(20, )
st art s0 s3
(10, )
(B , ) (10, )
(20, )
s2 (20, 10)
(R, )
(B , )
(R, )
(B , )
s1
(R, ) (10, )
(20, )
(B , ) (10, )
(20, )
s2 (20, 10)
(R, )
(B , )
(R, )
(B , )
s1 (R,M)
(R, ) (10, )
(20, )
(B , ) (10, )
(20, )
s2 (20, 10)
(B ,T )
(R, )
(B , )
For simplicity, we assume t hat xn and yn are bot h 0 (so t hat we can
avoid making special arrangement s concerning t he sum bit zn+ 1 ).
A finit e st at e machine t o perform t his addit ion can t hen be const ruct ed
using only two st at es.
( 1 ) T he st art st at e s0 is used t o remember t hat t he carry bit is 0.
( 2 ) T he ot her st at e s1 is used t o remember t hat t he carry bit is 1.
Since t he input s t o t he machine are pairs of bit s, t here are four possible
input s. We represent t hese by
(1) 00 (when bot h bit s are 0),
(2) 01 (when t he first bit is 0 and t he second bit is 1),
(3) 10 (when t he first bit is 1 and t he second bit is 0),
(4) 11 (when both bits are 1).
s0 s1
st art
(11, 0)
s0 s1
st art
(11, 0)
s0 s1
(00, 1)
st art
(01, 1)
(11, 0)
s0 s1
(00, 1)
st art
(01, 1)
(11, 0)
(00, 0) s0 s1
(00, 1)
st art
(01, 1)
(11, 0)
(00, 0) s0 s1
(00, 1)
st art (10, 1)
(01, 1) (01, 0)
(11, 0)
(00, 0) s0 s1
(00, 1)
st art (10, 1)
(01, 1) (01, 0)
(11, 0)
(00, 0) s0 s1 (11, 1)
(00, 1)
st art (10, 1)
(01, 1) (01, 0)
(11, 0)
(00, 0) s0 s1 (11, 1)
(00, 1)
st art (10, 1) (10, 0)
st art s0 s1 s2
(0,0)
st art s0 s1 s2
(0,0)
(1,0)
st art s0 s1 s2
(0,0)
(1,0)
st art s0 s1 s2
(0,0)
(0,0)
(1,0)
st art (1,0)
s0 s1 s2
(0,0)
(0,0)
(1,0)
st art (1,0)
s0 s1 s2
(0,0)
(0,0)
(0,0)
(1,0)
st art (1,0)
s0 s1 s2 (1,1)
(0,0)
(0,0)
6.0 O UTLINE 2
CSC211 - DISCRETE METHOD SPRING 2015
1. Language Recognition
• One of t he most import ant applicat ions of finite st at e aut omat a is
in language recognit ion.
• T his applicat ion plays a fundament al role in t he design and
const ruct ion of compilers for programming languages.
• Language recognit ion is a (binary) decision problem.
• Inst ead of producing out put , t he machines have a set of final
st at es.
• A st ring is accept ed or recognised by t he machine if and only if it
takes t he st art ing st at e t o one of it s final st at es.
T he t ransit ion funct ion f can be ext ended from single input symbols t o
st rings of input symbols:
• Let x = x1 x2 x3 . . . xk be a st ring in I ∗.
• Let f (s1 , x) denot e t he st at e obt ained by using each successive
symbol of x (from left t o right ) as input , st art ing wit h st at e s1 .
• From s1 we go t o st at e s2 = f (s1 , x1 ), t hen t o st at e s3 = f (s2 , x2 )
and so on, unt il we reach f (s1 , x) = f (sk , xk ).
st art 0
s0 s1
Solut ion:
st art 0
s0 s1
Solut ion:
• T he only final st at e of M1 is s0 .
st art 0
s0 s1
Solut ion:
• T he only final st at e of M1 is s0 .
• T he st rings t hat t ake s0 t o it self are t hose consist ing of zero or
more consecut ive ones.
st art 0
s0 s1
Solut ion:
• T he only final st at e of M1 is s0 .
• T he st rings t hat t ake s0 t o it self are t hose consist ing of zero or
more consecut ive ones.
• Hence L(M1 ) = { 1n : n = 0, 1, 2, . . .} = 1∗
s1
0 0
st art
s0 1 s3 0, 1
1
0, 1
s2
Solut ion:
s1
0 0
st art
s0 1 s3 0, 1
1
0, 1
s2
Solut ion:
• T he only final st at e of M2 is s2 .
s1
0 0
st art
s0 1 s3 0, 1
1
0, 1
s2
Solut ion:
• T he only final st at e of M2 is s2 .
• T he st rings t hat t ake s0 t o s2 are 1 and 01.
s1
0 0
st art
s0 1 s3 0, 1
1
0, 1
s2
Solut ion:
• T he only final st at e of M2 is s2 .
• T he st rings t hat t ake s0 t o s2 are 1 and 01.
• Hence L(M2 ) = { 1, 01}
0 s2 0, 1
1
st art 1
s0 s1
0
s3 0, 1
Solut ion:
0 s2 0, 1
1
st art 1
s0 s1
0
s3 0, 1
Solut ion:
• T he only st rings t hat t ake s0 t o it self are λ , 0, 00, . . ., i.e. any
st ring of zero or more consecut ive 0s.
0 s2 0, 1
1
st art 1
s0 s1
0
s3 0, 1
Solut ion:
• T he only st rings t hat t ake s0 t o it self are λ , 0, 00, . . ., i.e. any
st ring of zero or more consecut ive 0s.
• T he only st rings t hat t ake s0 t o s3 are t hose consist ing of zero or
more consecut ive 0s, followed by 10, followed by any st ring.
0 s2 0, 1
1
st art 1
s0 s1
0
s3 0, 1
Solut ion:
• T he only st rings t hat t ake s0 t o it self are λ , 0, 00, . . ., i.e. any
st ring of zero or more consecut ive 0s.
• T he only st rings t hat t ake s0 t o s3 are t hose consist ing of zero or
more consecut ive 0s, followed by 10, followed by any st ring.
• Hence L(M3 ) = 0∗ ∪0∗10(0 ∪1) ∗
f : S × I → P (S )
Not e: Nondet erminist ic FSA can also have t ransit ion rules of t he form
f (s1 , λ ) = { s3 } . T hese are called λ -t ransit ions.
Solut ion:
State Input 0 Input 1
s1
s0 s0 , s1 s3
s1 s0 s1 , s3
st art
s2 s0 , s2 s0 s3
s3 s0 , s1 , s2 s1
Solut ion:
State Input 0 Input 1
s1
s0 s0 , s1 s3 0
0
s1 s0 s1 , s3
st art
s2 s0 , s2 s0 s3
s3 s0 , s1 , s2 s1
Solut ion:
State Input 0 Input 1
s1
s0 s0 , s1 s3 0
0
s1 s0 s1 , s3
st art 1
s2 s0 , s2 s0 s3
s3 s0 , s1 , s2 s1
Solut ion:
State Input 0 Input 1
s1
s0 s0 , s1 s3 0
0
s1 s0 s1 , s3
st art 0 1
s2 s0 , s2 s0 s3
s3 s0 , s1 , s2 s1
1
6.2 N ONDETERMINISTIC F INITE S TATE AUTOMATA 11
CSC211 - DISCRETE METHOD SPRING 2015
1
6.2 N ONDETERMINISTIC F INITE S TATE AUTOMATA 11
CSC211 - DISCRETE METHOD SPRING 2015
s1
a a
st art
s0 λ s3
b b
s2
Solut ion:
s1
a a
st art
s0 λ s3
b b
s2
Solut ion:
• s3 can be reached by t he st rings aa and bb.
s1
a a
st art
s0 λ s3
b b
s2
Solut ion:
• s3 can be reached by t he st rings aa and bb.
• s3 can also be reached by t he st ring aλ b, i.e. ab.
s1
a a
st art
s0 λ s3
b b
s2
Solut ion:
• s3 can be reached by t he st rings aa and bb.
• s3 can also be reached by t he st ring aλ b, i.e. ab.
• Hence L(M) = { aa, bb, ab}
Kleene’s Theorem
7.1 Kleene’s T heorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
7.2 Regular Grammars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
7.3 Kleene’s T heorem and t he P umping Lemma . . . . . . . . . . . . . . 13
7.0 O UTLINE 2
CSC211 - DISCRETE METHOD SPRING 2015
1. Kleene’s Theorem
• A st ring is accept ed or recognised by a FSA if and only if it t akes
t he st art ing st at e t o one of it s final st at es.
• Kleene’s t heorem says t hat finit e st at e aut omat a are precisely
t hose machines t hat recognise regular expressions.
We can use t he met hod of proof by induct ion t o show t hat every regular
language can be recognised by a finit e st at e aut omat on.
st art
s0
st art λ
s0 s1
st art a
s0 s1
s1 s1j s1F M1
λ
st art
su
λ
s2 s2j s2F M2
s1F s2F
λ
st art
s1 s2
λ
s1G s2G
M1 M2
s1i s1F
st art
sk s1
λ
s1j s1G
Solut ion:
sA
st art • s0 corresponds t o S
s0 • sA corresponds t o A
• sF is t he final st at e.
sF
Solut ion:
sA
1
st art • s0 corresponds t o S
s0 • sA corresponds t o A
• sF is t he final st at e.
sF
Solut ion:
sA
1
st art • s0 corresponds t o S
s0 • sA corresponds t o A
0 • sF is t he final st at e.
sF
Solut ion:
sA (0,1)
1
st art • s0 corresponds t o S
s0 • sA corresponds t o A
0 • sF is t he final st at e.
sF
Solut ion:
sA (0,1)
1
st art • s0 corresponds t o S
s0 1 • sA corresponds t o A
0 • sF is t he final st at e.
sF
s1 0
Example 7.2. Find a 1
regular grammar t hat st art
generates the regular set s0 0 1
recognised by this finite 0
st at e aut omat on. s2 1
s1 0
Example 7.2. Find a 1
regular grammar t hat st art
generates the regular set s0 0 1
recognised by this finite 0
st at e aut omat on. s2 1
V = { S, A, B , 0, 1}
s1 0
Example 7.2. Find a 1
regular grammar t hat st art
generates the regular set s0 0 1
recognised by this finite 0
st at e aut omat on. s2 1
V = { S, A, B , 0, 1}
T = { 0, 1}
s1 0
Example 7.2. Find a 1
regular grammar t hat st art
generates the regular set s0 0 1
recognised by this finite 0
st at e aut omat on. s2 1
V = { S, A, B , 0, 1}
T = { 0, 1}
P = { S → λ , S → 1A, S → 0B , S → 0, A → 0A,
A → 1B , A → 1, B → 0A, B → 1B , B → 1}
where S, A, B correspond t o s0 , s1 , s2 respect ively.
s0
st art
s0 a s1 a ... a si
st art
...
a a
si + 2 sj − 2
a a
si + 1 sj − 1
a a
s0 a s1 a ... a si
st art
...
a a
si + 2 sj − 2
a a
si + 1 sj − 1
a a
s0 a s1 a ... a si a ... a sN ... s2N
st art b b
3
b a
a
a
a 2 b
a,b
1 5
a,b a
4
b
Subset Construction Method
3
a
a
a
b
Step1
a 2 b
Construct a transition table showing
a,b all reachable states for every state
1 5
for every input signal.
a,b a
4
b
Subset Construction Method
3
b a
a
a
a 2 b
a,b
1 5
a,b a
4
b
Subset Construction Method
3 q δ(q,a) δ(q,b)
b a
a 1 {1,2,3,4,5} {4,5}
a
a 2 b 2 {3} {5}
a,b
1 5 3 ∅ {2}
b
5 ∅ ∅
Subset Construction Method
3 q δ(q,a) δ(q,b)
b a
a Starts here 1 {1,2,3,4,5} {4,5}
a
a 2 b 2 {3} {5}
a,b
1 5 3 ∅ {2}
b
5 ∅ ∅
Subset Construction Method
5 ∅ ∅
Fig2. Transition table Fig3. Subset Construction table
2 {3} {5}
3 ∅ {2}
4 {5} {4}
5 ∅ ∅
Fig2. Transition table Fig3. Subset Construction table
4 {5} {4}
5 ∅ ∅
Fig2. Transition table Fig3. Subset Construction table
4 {5} {4}
5 ∅ ∅
Step3
Repeat this process(step2) until no
more new states are reachable.
Fig2. Transition table Fig3. Subset Construction table
5 ∅ ∅
Fig2. Transition table Fig3. Subset Construction table
∅
Fig2. Transition table Fig3. Subset Construction table
∅
2
Fig2. Transition table Fig3. Subset Construction table
∅ ∅ ∅
2
Fig2. Transition table Fig3. Subset Construction table
∅ ∅ ∅
2 3 5
3
Fig2. Transition table Fig3. Subset Construction table
∅ ∅ ∅
Stops here as there are 2 3 5
no more reachable states
3 ∅ 2
Fig3. Subset Construction table Fig4. Resulting FA after applying
Subset Construction to fig1
a
q δ(q,a) δ(q,b)
1 {1,2,3,4,5} {4,5} 1,2,3,4,5
b 2,4,5 a
{1,2,3,4,5} {1,2,3,4,5} {2,4,5} 3,5
{4,5} 5 4 a
a,b a
{2,4,5} {3,5} {4,5} b
b
1 ∅ a
∅ ∅
3
5 b
b a,b
a
4 5 4
2
{3,5} ∅ 2
4,5
a
5 b
∅ ∅ ∅ b 4 a
2 3 5
b
3 ∅ 2