Date post: | 02-Jan-2016 |
Category: |
Documents |
Upload: | justin-clark |
View: | 60 times |
Download: | 0 times |
1010ภาษาภาษา
สม่ำ��าเสม่ำอสม่ำ��าเสม่ำอREGULAR LANGUAGESREGULAR LANGUAGES
วั�ตถุ�ประสงค์�วั�ตถุ�ประสงค์�Language defined by regular Language defined by regular expression is called aexpression is called a
regular regular languageslanguages..
All languages are regular ? (YES/NO)All languages are regular ? (YES/NO)
Discuss some Discuss some propertiesproperties of all of all
regular languages.regular languages.
REGULAR LANGUAGES
REGULAR LANGUAGESภาษาสม่ำ��าเสม่ำอภาษาสม่ำ��าเสม่ำอLet LLet L11 and L and L22 be regular languages. be regular languages.
Then LThen L11+L+L22, L, L11LL22 and L and L11* are also* are also
regular languages.regular languages.
Proof: Proof:
By definition of regular expression,By definition of regular expression,
regular expression is closed under regular expression is closed under union,union,
concatenate and Kleene star.concatenate and Kleene star.
ทฤษฎี�บททฤษฎี�บท
REGULAR LANGUAGES
What’s about finite automata?
Find LFind L11+L+L22
q2
b
q3
b
q0q1
a
a a a
b
b
q4
q5
ba,b
a
q6
REGULAR LANGUAGESภาษาสม่ำ��าเสม่ำอภาษาสม่ำ��าเสม่ำอREGULAR LANGUAGES
Find LFind L11LL22
q2
b
q3b
q0q1
a
a a a
b
b
q4
q5
ba,b
a
REGULAR LANGUAGESภาษาสม่ำ��าเสม่ำอภาษาสม่ำ��าเสม่ำอREGULAR LANGUAGES
Find LFind L11**
q2
b
q3b
q0q1
a
a a a
b
b
qk
REGULAR LANGUAGESภาษาสม่ำ��าเสม่ำอภาษาสม่ำ��าเสม่ำอREGULAR LANGUAGES
นิ�ยาม่ำนิ�ยาม่ำIf L is a language over the alphabet If L is a language over the alphabet ..
The complement of L denoted by L’ is The complement of L denoted by L’ is
the language of all strings of characters the language of all strings of characters
from from that are not words in L. that are not words in L.
The complement of L = The complement of L = * - L.* - L.
Notice that the complement of L’ is L. ( (L’)’=L.)Notice that the complement of L’ is L. ( (L’)’=L.)
COMPLEMENT
REGULAR LANGUAGESภาษาสม่ำ��าเสม่ำอภาษาสม่ำ��าเสม่ำอREGULAR LANGUAGES
Let L be a regular language.Let L be a regular language.Then L’ is also a regular language.Then L’ is also a regular language.(closed under complementation)(closed under complementation)
Proof: Proof: By Kleene’s theorem, there is some FA thatBy Kleene’s theorem, there is some FA thataccepts the language L. By reversing all finalaccepts the language L. By reversing all finalstates in that FA into non-final states, andstates in that FA into non-final states, andall non-final states into final states, the newall non-final states into final states, the newmachine is a FA that accepts L’.machine is a FA that accepts L’.By Kleene’s theorem, L’ is a regular By Kleene’s theorem, L’ is a regular
language.language.QED.QED.
REGULAR LANGUAGESภาษาสม่ำ��าเสม่ำอภาษาสม่ำ��าเสม่ำอREGULAR LANGUAGES
ทฤษฎี�บททฤษฎี�บท
EXAMPLE:EXAMPLE:Given Given ={a, b},={a, b},and L = a(a+b)*.and L = a(a+b)*.Find L’.Find L’.
q0
q1
a
a, b
bq2
a, b
REGULAR LANGUAGESภาษาสม่ำ��าเสม่ำอภาษาสม่ำ��าเสม่ำอREGULAR LANGUAGES
q0
q1
a
a, b
bq2
a, b
This FA accepts all words started with b, and also .L’ = +b(a+b)*
REGULAR LANGUAGESภาษาสม่ำ��าเสม่ำอภาษาสม่ำ��าเสม่ำอREGULAR LANGUAGES
EXAMPLE:EXAMPLE:Given Given ={a, b},={a, b},and L = a(a+b)*.and L = a(a+b)*.Find L’.Find L’.
Let LLet L11 and L and L22 be regular languages. be regular languages.
Then LThen L11LL22 is also a regular is also a regular language.language.
Proof: Proof:
By DeMorgan’s law for sets,By DeMorgan’s law for sets,
LL11LL22 = (L = (L11’+L’+L22’)’.’)’.
So, LSo, L11LL22 is a regular language. is a regular language.
QED.QED.
INTERSECTIONREGULAR LANGUAGESภาษาสม่ำ��าเสม่ำอภาษาสม่ำ��าเสม่ำอ
REGULAR LANGUAGES
ทฤษฎี�บททฤษฎี�บทHow to construct a finite automaton
associated with the language?
LL11 = language((a+b)*aa(a+b)*) L = language((a+b)*aa(a+b)*) L22 = = language(b*(ab*ab*)*)language(b*(ab*ab*)*)
q2
b
q0 q1aa
a, b
bb
q3 q4
ba
a
REGULAR LANGUAGESภาษาสม่ำ��าเสม่ำอภาษาสม่ำ��าเสม่ำอREGULAR LANGUAGES
q2
b
q0 q1aa
a, b
bb
q3 q4
ba
a
Find L1’ and L2’
REGULAR LANGUAGESภาษาสม่ำ��าเสม่ำอภาษาสม่ำ��าเสม่ำอREGULAR LANGUAGES
LL11 = language((a+b)*aa(a+b)*) L = language((a+b)*aa(a+b)*) L22 = = language(b*(ab*ab*)*)language(b*(ab*ab*)*)
q2
b
q0 q1aa
a, b
bb
q3 q4
ba
a
0,3a
1,4
b
a2,3
0,4
b
a2,4
ba
b
1,3ab
a
b
REGULAR LANGUAGESภาษาสม่ำ��าเสม่ำอภาษาสม่ำ��าเสม่ำอREGULAR LANGUAGES
Let LLet L11 L L22 be regular languages associated with be regular languages associated with
machines Mmachines M11=(Q=(Q11,,,q,q11,A,,A,11) and M) and M22=(Q=(Q22,,,q,q22,A,,A,22).).
Let M =(QLet M =(Q11QQ22,,,(q,(q1 1 ,q,q22),A,),A,) and transition function) and transition function
is defined by the formulais defined by the formula
((p,q),a) = (((p,q),a) = (11(p,a),(p,a),22(q,a)).(q,a)).
ThenThen
if A={(p,q)|pif A={(p,q)|pAA11 or q or qAA22}, M accepts the L}, M accepts the L11LL22..
if A={(p,q)|pif A={(p,q)|pAA11 and q and qAA22}, M accepts the L}, M accepts the L11LL22..
if A={(p,q)|pif A={(p,q)|pAA11 and q and qAA22}, M accepts the L}, M accepts the L11-L-L22..
SUMMARYREGULAR LANGUAGESภาษาสม่ำ��าเสม่ำอภาษาสม่ำ��าเสม่ำอ
REGULAR LANGUAGES
ทฤษฎี�บททฤษฎี�บท
โจทย์� น่�าคิ�ดน่�าคิ�ด
?A
B
C
1
0
1,0
X Y
0
1
0,10
จจงหาออโตม่ำาตาจ�ากั�ดงหาออโตม่ำาตาจ�ากั�ดส�าหร�บภาษา ส�าหร�บภาษา LL11LL22
L1
L2
1111REGULARREGULARDECIDABLEDECIDABLE
REGULARITY
ค์�ณสม่ำบ�ต�ค์วัาม่ำค์�ณสม่ำบ�ต�ค์วัาม่ำสม่ำ��าเสม่ำอสม่ำ��าเสม่ำอ
A language is regular (describable by a A language is regular (describable by a regular expression) if and only if it can regular expression) if and only if it can
be accepted by a finite automaton.be accepted by a finite automaton.
What inherent property of a language What inherent property of a language identifies it as being regular ?identifies it as being regular ?
REGULAR DECIDABLE
PALINDROME is not regular.PALINDROME is not regular.Since there are infinitely many Since there are infinitely many distinguishable.distinguishable.
RemarkRemarkLanguage L contains infinitely manyLanguage L contains infinitely many
““pairwise distinguishablepairwise distinguishable””with respect to Lwith respect to Lthen L cannot be regular.then L cannot be regular.
REGULARITY
ค์�ณสม่ำบ�ต�ค์วัาม่ำค์�ณสม่ำบ�ต�ค์วัาม่ำสม่ำ��าเสม่ำอสม่ำ��าเสม่ำอ
REGULAR DECIDABLE
What is the relationship betweenWhat is the relationship betweenregular and distinguishable ?regular and distinguishable ?
Define a relation:Define a relation:We will say that two strings areWe will say that two strings are equivalentequivalent if they areif they are indistinguishableindistinguishable with respect to L.with respect to L.
REGULARITY
ค์�ณสม่ำบ�ต�ค์วัาม่ำค์�ณสม่ำบ�ต�ค์วัาม่ำสม่ำ��าเสม่ำอสม่ำ��าเสม่ำอ
REGULAR DECIDABLE
INDISTINGUISHABILITY
ค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'ค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัต'างกั�นิได(แตกัต'างกั�นิได(
Let L be any language in Let L be any language in *. The relation *. The relation IILL on on
*( *( the indistinguishability relation) is ) is defined as follows:defined as follows:For any two strings x, y in For any two strings x, y in *, *,
xxIILLy if and only ify if and only if x and y are indistinguishablex and y are indistinguishablewith respect to L.with respect to L.
In other words, xILy if for any z in *,either xz and yz are both in L
or xz and yz are both in L’.
REGULAR DECIDABLE
ต�วัอย'างต�วัอย'างL be a language over L be a language over =(0, 1}, defined as =(0, 1}, defined as
follows;follows;x x L with length(x) > 0, L with length(x) > 0,x does not contain “double characters”.x does not contain “double characters”.
Regular expression of L = (0+)(10)*(1+).
For instance, 0101 For instance, 0101 IILL 10101 since they are 10101 since they are indistinguishable with respect to L.indistinguishable with respect to L.For any z For any z *,*,
if 0101z is in L, then 10101z is also in L,if 0101z is in L, then 10101z is also in L,if 0101z is not in L, then 10101z is not in L.if 0101z is not in L, then 10101z is not in L.
INDISTINGUISHABILITY
ค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'ค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัต'างกั�นิได(แตกัต'างกั�นิได(
REGULAR DECIDABLE
INDISTINGUISHABILITY
ค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'ค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัต'างกั�นิได(แตกัต'างกั�นิได(
REGULAR DECIDABLE
LEMMA
For any language L,For any language L,IILL is an equivalence relation on is an equivalence relation on *.*.
Let x, y and z be strings in Let x, y and z be strings in *.*.Reflexive: xReflexive: xIILLxxSymmetric: if xSymmetric: if xIILLy then yy then yIILLxxTransitivity: if xTransitivity: if xIILLy and yy and yIILLz then xz then xIILLz.z.
INDISTINGUISHABILITY
ค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'ค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัต'างกั�นิได(แตกัต'างกั�นิได(
REGULAR DECIDABLE
Proof
It is obvious for reflexive and symmetric.It is obvious for reflexive and symmetric.Let x, y and z be strings in Let x, y and z be strings in *.*.Given xGiven xIILLy and yy and yIILLz, and for any a z, and for any a *.*.Suppose that xa is in L,Suppose that xa is in L,we will show that za is in L.we will show that za is in L.
Since xa is in L and xSince xa is in L and xIILLy, ya is also in L.y, ya is also in L.Since ya is in L and ySince ya is in L and yIILLz, za is in L.z, za is in L.thus xthus xIILLz.z. Q.E.D.Q.E.D.
INDISTINGUISHABILITY
ค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัต'างกั�นิได(ต'างกั�นิได(
REGULAR DECIDABLE
ต�วัอย'างต�วัอย'างL be a language over L be a language over =(0, 1}, defined as =(0, 1}, defined as
follows;follows;x x L with length(x) > 0, L with length(x) > 0,x does not contain “double characters”.x does not contain “double characters”.
Regular expression of L = (0+Regular expression of L = (0+)(10)*(1+)(10)*(1+).).
[[] = { ] = { } }[1] = { 1, 01, 101, 0101, …}[1] = { 1, 01, 101, 0101, …}[0] = { 0, 10, 010, 1010, ... }[0] = { 0, 10, 010, 1010, ... }
[00+11] = { 00, 11, 000, 011, 111, … }[00+11] = { 00, 11, 000, 011, 111, … }
INDISTINGUISHABILITY
ค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัต'างกั�นิได(ต'างกั�นิได(
REGULAR DECIDABLE
ข้(อส�งเกัต�ข้(อส�งเกัต�
If the set of all equivalence classes of If the set of all equivalence classes of IILLis finite, then it is possible to constructis finite, then it is possible to constructan DFA recognizing L in terms of thean DFA recognizing L in terms of theequivalence classes of equivalence classes of IILL..
Automaton M=(Q, Automaton M=(Q, , q, q00, A, , A, ))LLqq = { x = { x | | *(q*(q00, x) = q }, x) = q }for q for q Q. Q.
LLqq is the set of all strings that end in the state q of is the set of all strings that end in the state q of M.M.
What is the relationship between them ?
INDISTINGUISHABILITY
ค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัต'างกั�นิได(ต'างกั�นิได(
REGULAR DECIDABLE
ข้(อส�งเกัต�ข้(อส�งเกัต�
LA = { }LB = { 0, 010, 01010, 0101010, … }LC = { 01,0101, 010101, 01010101, … }LD = { 1, 101, 10101, 1010101, … }LE = { 10, 1010, 101010, 10101010, … }L = { 00, 11, 000, 001, 100, 111, … }
B0
C1
A
D1
E0
1
0,1
0
1
1
0
0
INDISTINGUISHABILITY
ค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัต'างกั�นิได(ต'างกั�นิได(
REGULAR DECIDABLE
ต�วัอย'างต�วัอย'าง
If number of classes of If number of classes of IILL and L and Lqq are the same, then are the same, then•two partitions are identical andtwo partitions are identical and•FA is the fewest possible states recognizing L.FA is the fewest possible states recognizing L.
For strings x in For strings x in * and a in * and a in
([x], a) = [xa].
INDISTINGUISHABILITY
ค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัต'างกั�นิได(ต'างกั�นิได(
REGULAR DECIDABLE
หม่ำายเหต�หม่ำายเหต�
IILL is is right invariant with respect to concatenation. with respect to concatenation.For any x, y in For any x, y in *, and any a in *, and any a in ,,if x if x IIL L y, then xa y, then xa IIL L ya.ya.Equivalently, if [x] = [y], then [xa] = [ya].Equivalently, if [x] = [y], then [xa] = [ya].
Proof:Let x IL y. Then x and y are indistinguishable with respectto L. For any z in *, if xz is in L, then yz is in L.Consider xaz, for any a in *, if xaz is in L and let z’ = az,then yz’ is also in L. Thus xa IL ya. Q.E.D.
INDISTINGUISHABILITY
ค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัต'างกั�นิได(ต'างกั�นิได(
REGULAR DECIDABLE
LEMMALEMMA
Let L Let L *, and Q*, and QLL be the set of equivalence classes be the set of equivalence classes of the relation of the relation IILL on on *.*.If QIf QLL is a finite set, then M is a finite set, then ML L = (Q= (QLL, , , q, q00, A, ALL, , ) is a ) is a finite automaton accepting L, wherefinite automaton accepting L, where
•qq00 = [ = []]•AALL = { q in Q = { q in QLL | q | q L L } and } and: Q: QLL Q QLL is defined by is defined by ([x],a) = [xa].([x],a) = [xa].
Furthermore,Furthermore,MMLL has the fewest states of any FA accepting L. has the fewest states of any FA accepting L.
INDISTINGUISHABILITY
ค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัต'างกั�นิได(ต'างกั�นิได(
REGULAR DECIDABLE
ทฤษฎี�บททฤษฎี�บท
If QIf QLL is a finite set, then M is a finite set, then MLL is finite. is finite.Now, MNow, MLL= (Q= (QLL, , , q, q00, A, ALL, , ) recognizes the language L.) recognizes the language L.For any x For any x *, x *, x L if and only if L if and only if *(q*(q00,x) ,x) A ALL..Let x Let x L. Since x L. Since x [x], we have that x [x], we have that x [x] [x] L L ..Since Since *(q*(q00,x) = ,x) = ([([],x) = [x] ],x) = [x] A ALL..
For u, v For u, v *, (*, (([u], v) = [uv])([u], v) = [uv])If If *(q*(q00,x) ,x) A ALL, then [x] , then [x] L L ..Let y be an element in [x] Let y be an element in [x] L. We have that y L. We have that y L. L.x and y are indistinguishable (same class), then x x and y are indistinguishable (same class), then x L.L.
INDISTINGUISHABILITY
ค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัต'างกั�นิได(ต'างกั�นิได(
REGULAR DECIDABLE
พิ�ส+จนิ�พิ�ส+จนิ�
MYHILL-NERODE THEOREM
L is a L is a regularregular if and only if Q if and only if QLL is is finitefinite..
QQLL is finite, M is finite, MLL is also finite. is also finite.([x],y) = [xy] for any strings x and y in ([x],y) = [xy] for any strings x and y in *.*.
The partition LThe partition Lqq is finer than the partition is finer than the partition IILL..
INDISTINGUISHABILITY
ค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัต'างกั�นิได(ต'างกั�นิได(
REGULAR DECIDABLE
ทฤษฎี�บททฤษฎี�บท
Let L = { x in {0, 1}* | x ends with 10 }.Let L = { x in {0, 1}* | x ends with 10 }.Consider three strings, Consider three strings, , 1 and 10. Ant two of these , 1 and 10. Ant two of these strings are distinguishable with respect to L.strings are distinguishable with respect to L.
[[] = { ] = { , 0, 1, 00, 000, 100, 0000, 0100, … }, 0, 1, 00, 000, 100, 0000, 0100, … }
[1] = { 1, 01, 001, 0001, 00001, … }[1] = { 1, 01, 001, 0001, 00001, … }
[10] = { 10, 010, 110, 0010, … }.[10] = { 10, 010, 110, 0010, … }.
INDISTINGUISHABILITY
ค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัต'างกั�นิได(ต'างกั�นิได(
REGULAR DECIDABLE
ต�วัอย'าต�วัอย'างง
Let L = { x in {0, 1}* | x ends with 10 }.Let L = { x in {0, 1}* | x ends with 10 }.Consider three strings, Consider three strings, , 1 and 10. Ant two of these , 1 and 10. Ant two of these strings are distinguishable with respect to L.strings are distinguishable with respect to L.
MMLL = (Q = (QLL, {0, 1}, [, {0, 1}, [], {[10]}, ], {[10]}, ) be the FA, and) be the FA, and
([([], 0) = [], 0) = []] ([([], 1) = [1]], 1) = [1]([1], 0) = [10]([1], 0) = [10] ([1], 1) = [1]([1], 1) = [1]([10], 0) = [([10], 0) = []] ([10], 1) = [1].([10], 1) = [1].
INDISTINGUISHABILITY
ค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัต'างกั�นิได(ต'างกั�นิได(
REGULAR DECIDABLE
ต�วัอย'าต�วัอย'างง
[] [1]1
[10]0
0
10
DFA1
Let L = { x in {0, 1}* | x ends with 10 }.Let L = { x in {0, 1}* | x ends with 10 }.Consider three strings, Consider three strings, , 1 and 10. Ant two of these , 1 and 10. Ant two of these strings are distinguishable with respect to L.strings are distinguishable with respect to L.
INDISTINGUISHABILITY
ค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัต'างกั�นิได(ต'างกั�นิได(
REGULAR DECIDABLE
ต�วัอย'าต�วัอย'างง
โจทย์� น่�าคิ�ดน่�าคิ�ด
?กั�าหนิดให( ภาษากั�าหนิดให( ภาษา 0n1n เม่ำ,�อ เม่ำ,�อ n n 00
{ { , 01, 0011, 000111, … }, 01, 0011, 000111, … }
จงแสดงให(เห-นิวั'าจงแสดงให(เห-นิวั'า
ภาษานิ�.ไม่ำ'เป/นิภาษาภาษานิ�.ไม่ำ'เป/นิภาษาสม่ำ��าเสม่ำอสม่ำ��าเสม่ำอ
L = { 0L = { 0nn11nn | n | n 0 }, show that L is not 0 }, show that L is not regular.regular.
Consider any strings of the form 0Consider any strings of the form 0ii and 0 and 0jj with i with i i. i.They are distinguished by the string 1They are distinguished by the string 1ii..
They are infinitely many strings of the form 0They are infinitely many strings of the form 0ii and 0 and 0jj..
Then there are infinitely many distinguished strings.Then there are infinitely many distinguished strings.
INDISTINGUISHABILITY
ค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัต'างกั�นิได(ต'างกั�นิได(
REGULAR DECIDABLE
ต�วัอย'าต�วัอย'างง
โจทย์� น่�าคิ�ดน่�าคิ�ด
?กั�าหนิดให( ภาษากั�าหนิดให( ภาษา ww เม่ำ,�อ เม่ำ,�อ w w **
{ { , 00, 11, 0000, 0101, … }, 00, 11, 0000, 0101, … }
จงแสดงให(เห-นิวั'าจงแสดงให(เห-นิวั'า
ภาษานิ�.ไม่ำ'เป/นิภาษาภาษานิ�.ไม่ำ'เป/นิภาษาสม่ำ��าเสม่ำอสม่ำ��าเสม่ำอ
L = { ww| w L = { ww| w {0, 1}* }, show that L is not {0, 1}* }, show that L is not regular.regular.
Consider any strings of the form 0Consider any strings of the form 0ii and 0 and 0jj with i with i i. i.They are distinguished by the string 1They are distinguished by the string 1ii00ii11ii..
They are infinitely many strings of the form 0They are infinitely many strings of the form 0ii and 0 and 0jj..
Then there are infinitely many distinguished strings.Then there are infinitely many distinguished strings.
INDISTINGUISHABILITY
ค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัต'างกั�นิได(ต'างกั�นิได(
REGULAR DECIDABLE
ต�วัอย'าต�วัอย'างง
Number of equivalence classesNumber of equivalence classes= number of states in M= number of states in MLL
then Mthen MLL is a minimal finite state machine. is a minimal finite state machine.
Find a pair (LFind a pair (Lpp, L, Lqq) such that L) such that Lpp and L and Lqq are in the same are in the same class, group it into one class.class, group it into one class.
By contraposition, we will find a pair (LBy contraposition, we will find a pair (Lpp, L, Lqq) that they ) that they are in difference classes.are in difference classes.
INDISTINGUISHABILITY
ค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัต'างกั�นิได(ต'างกั�นิได(
REGULAR DECIDABLE
MINIMAL FINITE STATE MACHINE
For p and q in Q, p For p and q in Q, p q, if and only if q, if and only ifThere exists z in There exists z in * so that* so that
exactly one of the two states exactly one of the two states *(p,z) and *(p,z) and (q,z)(q,z)is in A.is in A.
A pair (p, q) of states for which LA pair (p, q) of states for which Lpp and L and Lqq are subsets are subsets of different equivalence classes, denoted by p of different equivalence classes, denoted by p q. q.
INDISTINGUISHABILITY
ค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัต'างกั�นิได(ต'างกั�นิได(
REGULAR DECIDABLE
MINIMAL FINITE STATE MACHINE
LEMMALEMMA
For p and q in Q, p For p and q in Q, p q, q,if and only if there exists z in if and only if there exists z in * so that* so that
exactly one of the two states exactly one of the two states *(p,z) and *(p,z) and (q,z)(q,z)is in A.is in A.
Proof:Proof:Let p Let p q. Let x is in L q. Let x is in Lpp and y is in L and y is in Lqq, we have that , we have that there exists z in there exists z in *, xz and yz are distinguishable,*, xz and yz are distinguishable,
*(p,z) = *(p,z) = *(*(*(q*(q00,x),z) = ,x),z) = *(q*(q00,xz),xz)*(q,z) = *(q,z) = *(*(*(q*(q00,y),z) = ,y),z) = *(q*(q00,yz) only one is in ,yz) only one is in
L.L.Suppose that only one of Suppose that only one of *(p,z) and *(p,z) and (q,z) is in A.(q,z) is in A.It means that z distinguishes x in LIt means that z distinguishes x in Lpp and y in L and y in Lqq with with respect to L. Therefore p respect to L. Therefore p q. q.
INDISTINGUISHABILITY
ค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัต'างกั�นิได(ต'างกั�นิได(
REGULAR DECIDABLE
MINIMAL FINITE STATE MACHINELEMMALEMMA
Consider (p,q) be a Consider (p,q) be a distinguishabledistinguishable pair. pair.Let r and s be two states in Q.Let r and s be two states in Q.For some a in For some a in , such that , such that (r,a) = p and (r,a) = p and (s,a) = q.(s,a) = q.
SinceSince*(r,az) = *(r,az) = *(*(*(r,a)) = *(r,a)) = *(p,z)*(p,z)*(s,az) = *(s,az) = *(*(*(s,a)) = *(s,a)) = *(q,z),*(q,z),
we can conclude that (r,s) is also be a we can conclude that (r,s) is also be a distinguishabledistinguishable pair. pair.
INDISTINGUISHABILITY
ค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัต'างกั�นิได(ต'างกั�นิได(
REGULAR DECIDABLE
MINIMAL FINITE STATE MACHINE
6
7
4
5
3
2
1
0
1
1
0
10
0
1
1
0
0
1
0
1
(0+1)*(01)
INDISTINGUISHABILITY
ค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัต'างกั�นิได(ต'างกั�นิได(
REGULAR DECIDABLE
MINIMAL FINITE STATE MACHINE
ต�วัอย'าต�วัอย'างง
ALGORITHM
22
33 22 22
44 22
55 22 22 22
66 11 11 11 11 11
77 22 22 22 11
11 22 33 44 55 66
State class class class#1 #2 #3
1 12 1,23 34 1,2,45 3,56 67 3,5,7
INDISTINGUISHABILITY
ค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัค์วัาม่ำสาม่ำารถุในิกัารแยกัค์วัาม่ำไม่ำ'แตกัต'างกั�นิได(ต'างกั�นิได(
REGULAR DECIDABLE
MINIMAL FINITE STATE MACHINE
AlgorithmAlgorithm
A Language that cannot be A Language that cannot be defined by a regular expression defined by a regular expression is called a is called a nonregularnonregular language. language.
NONREGULAR
ค์วัาม่ำไม่ำ'ค์วัาม่ำไม่ำ'สม่ำ��าเสม่ำอสม่ำ��าเสม่ำอ
REGULAR DECIDABLE
Given an infinite regular language LGiven an infinite regular language L
Suppose that there exists a FA with n states Suppose that there exists a FA with n states associated with L.associated with L.
For any word x in L such that |x| For any word x in L such that |x| n, n, consider a path associated with x,consider a path associated with x,
qq00qq11qq22…q…qn+1n+1
then, there exists qthen, there exists qii = q = qjj where i where i j. j.
NONREGULAR
ค์วัาม่ำไม่ำ'ค์วัาม่ำไม่ำ'สม่ำ��าเสม่ำอสม่ำ��าเสม่ำอ
REGULAR DECIDABLE
บทวั�เค์ราะห�บทวั�เค์ราะห�
a a a a1 2 3 9
a
a
a
a
a
a2a*a7b10 accepteda2a2a7b10 accepted
a2(ak)*a6b10 accepteda2a2ka6b10 accepted
a10b10
NONREGULAR
ค์วัาม่ำไม่ำ'ค์วัาม่ำไม่ำ'สม่ำ��าเสม่ำอสม่ำ��าเสม่ำอ
REGULAR DECIDABLE
บทวั�เค์ราะห�บทวั�เค์ราะห�
FA with 9 states
Suppose L is a regular language recognizedSuppose L is a regular language recognizedby a finite automaton with n states.by a finite automaton with n states.
For any u For any u L, with L, with |u||u| n n,,there are strings x, y and z so that there are strings x, y and z so that
u = xyzu = xyz|xy||xy| n ny y
For any m For any m 0, 0, xyxymmz z L L..
NONREGULAR
ค์วัาม่ำไม่ำ'ค์วัาม่ำไม่ำ'สม่ำ��าเสม่ำอสม่ำ��าเสม่ำอ
REGULAR DECIDABLE
ทฤษฎี�บททฤษฎี�บท
x z
y
xy*z is also accepted by this finite automaton.
NONREGULAR
ค์วัาม่ำไม่ำ'ค์วัาม่ำไม่ำ'สม่ำ��าเสม่ำอสม่ำ��าเสม่ำอ
REGULAR DECIDABLE
ทฤษฎี�บททฤษฎี�บท
For any u For any u L, L, |u||u| n n. Let u = u. Let u = u11uu22uu33…u…umm; m ; m n n
By the By the pigeonhole principlepigeonhole principle, ,
there exist uthere exist uii and u and ujj such that such that
*(q*(q00,u,u11uu22…u…uii) = q) = qii and and *(q*(q00,u,u11uu22…u…uii…u…ujj) = q) = qii
It is clear that It is clear that *(q*(qii,u,ui+1i+1uui+2i+2…u…ujj) = q) = qii
We also have that |uWe also have that |u11uu22…u…uii…u…ujj| | n. n.
Let x = uLet x = u11uu22…u…uii, y = u, y = ui+1i+1uui+2i+2…u…ujj and z = u and z = uj+1j+1uuj+2j+2…u…umm..
For any m For any m 0, 0, xyxymmz z L L..
NONREGULAR
ค์วัาม่ำไม่ำ'ค์วัาม่ำไม่ำ'สม่ำ��าเสม่ำอสม่ำ��าเสม่ำอ
REGULAR DECIDABLE
ทฤษฎี�บททฤษฎี�บท
NONREGULAR
ค์วัาม่ำไม่ำ'ค์วัาม่ำไม่ำ'สม่ำ��าเสม่ำอสม่ำ��าเสม่ำอ
REGULAR DECIDABLE
ทฤษฎี�บททฤษฎี�บทPUMPING LEMMAPUMPING LEMMAFOR REGULAR LANGUAGEFOR REGULAR LANGUAGEL be a regular language.L be a regular language.
There is an integer n so that for any u in L,There is an integer n so that for any u in L,with |u|with |u| n, there are strings x, y and z n, there are strings x, y and zso that so that
u = xyzu = xyz|xy||xy| n n|y| > 0|y| > 0for any m for any m 0, xy 0, xymmz is in L.z is in L.
โจทย์� น่�าคิ�ดน่�าคิ�ด
?กั�าหนิดให( ภาษากั�าหนิดให( ภาษา 0n1n เม่ำ,�อ เม่ำ,�อ n n 00
{ { , 01, 0011, 000111, … }, 01, 0011, 000111, … }
จงแสดงให(เห-นิวั'าจงแสดงให(เห-นิวั'า
ภาษานิ�.ไม่ำ'เป/นิภาษาภาษานิ�.ไม่ำ'เป/นิภาษาสม่ำ��าเสม่ำอสม่ำ��าเสม่ำอ
USING PUMPING LEMMAUSING PUMPING LEMMA
โจทย์� น่�าคิ�ดน่�าคิ�ด
?กั�าหนิดให( ภาษากั�าหนิดให( ภาษา ww เม่ำ,�อ เม่ำ,�อ w w **
{ { , 00, 11, 0000, 0101, … }, 00, 11, 0000, 0101, … }
จงแสดงให(เห-นิวั'าจงแสดงให(เห-นิวั'า
ภาษานิ�.ไม่ำ'เป/นิภาษาภาษานิ�.ไม่ำ'เป/นิภาษาสม่ำ��าเสม่ำอสม่ำ��าเสม่ำอ
USING PUMPING LEMMAUSING PUMPING LEMMA
โจทย์� น่�าคิ�ดน่�าคิ�ด
?กั�าหนิดให( ภาษากั�าหนิดให( ภาษา
{0{0kkw | w w | w {0,1}* and |w| {0,1}* and |w| k } k }
จงแสดงให(เห-นิวั'าจงแสดงให(เห-นิวั'า
ภาษานิ�.ไม่ำ'เป/นิภาษาภาษานิ�.ไม่ำ'เป/นิภาษาสม่ำ��าเสม่ำอสม่ำ��าเสม่ำอ
USING PUMPING LEMMAUSING PUMPING LEMMA
โจทย์� น่�าคิ�ดน่�าคิ�ด
?กั�าหนิดให( ภาษากั�าหนิดให( ภาษา
{ w { w {0,1}* | n {0,1}* | n00(w) = n(w) = n11(w) }(w) }
จงแสดงให(เห-นิวั'าจงแสดงให(เห-นิวั'าภาษานิ�.ไม่ำ'เป/นิภาษาสม่ำ��าเสม่ำอภาษานิ�.ไม่ำ'เป/นิภาษาสม่ำ��าเสม่ำอ
USING PUMPING LEMMAUSING PUMPING LEMMA
โจทย์� น่�าคิ�ดน่�าคิ�ด
?กั�าหนิดให( ภาษากั�าหนิดให( ภาษา
{ 0{ 0kk | k is a prime number } | k is a prime number }
จงแสดงให(เห-นิวั'าจงแสดงให(เห-นิวั'า
ภาษานิ�.ไม่ำ'เป/นิภาษาภาษานิ�.ไม่ำ'เป/นิภาษาสม่ำ��าเสม่ำอสม่ำ��าเสม่ำอ
USING PUMPING LEMMAUSING PUMPING LEMMA
1212DECISIONDECISIONPROBLEMPROBLEM
บทสร�ปบทสร�ปA finite automaton receives the A finite automaton receives the input string, and results in the input string, and results in the output “accept” or “reject”.output “accept” or “reject”.
DECISION PROBLEM
DECISION PROBLEM
ป0ญหาต�ดส�นิใจป0ญหาต�ดส�นิใจA computational problem thatA computational problem thata finite automaton can solved a finite automaton can solved are called “are called “decision decision problemsproblems”.”.
This means that the problem This means that the problem can be answered “can be answered “yesyes” or ” or ““nono”.”.
DECISION PROBLEM
A Limitation of a finite automaton.A Limitation of a finite automaton.The problem requires instancesThe problem requires instancesto remember more than someto remember more than somefixed amount of information.fixed amount of information.
The generic decision problem thatThe generic decision problem thatcan be solved by a finite automatoncan be solved by a finite automatonis the “is the “membership problemmembership problem” for” forthe corresponding regular language.the corresponding regular language.
DECISION PROBLEM
ป0ญหาต�ดส�นิใจป0ญหาต�ดส�นิใจDECISION PROBLEM
Given a finite automaton M, Given a finite automaton M, and string x, the question is if and string x, the question is if x is a string in L(M).x is a string in L(M).
Informally, this can be solved Informally, this can be solved in |x| steps of computation.in |x| steps of computation.
DECISION PROBLEM
ป0ญหาต�ดส�นิใจป0ญหาต�ดส�นิใจDECISION PROBLEM
MEMBERSHIP PROBLEMMEMBERSHIP PROBLEM
Given a finite automaton M,Given a finite automaton M,is there a string that it accepts?is there a string that it accepts?is L(M) finite?is L(M) finite?is it a minimum-state automaton accepting L(M)?is it a minimum-state automaton accepting L(M)?
Given two finite automata MGiven two finite automata M11 and M and M22,,are there any strings that are accepted by both?are there any strings that are accepted by both?do they accept the same language?do they accept the same language?is L(Mis L(M11) is a subset of L(M) is a subset of L(M22)?)?
Given two regular expressions rGiven two regular expressions r11 and r and r22,,do they correspond to the same language?do they correspond to the same language?
DECISION PROBLEM
ป0ญหาต�ดส�นิใจป0ญหาต�ดส�นิใจDECISION PROBLEM
MEMBERSHIP PROBLEMMEMBERSHIP PROBLEM
โจทย์� น่�าคิ�ดน่�าคิ�ด
?จงหา ภาษาท�� ท�กัจงหา ภาษาท�� ท�กัequivalence classequivalence class ข้อง ข้อง IILL ม่ำ�สม่ำาชิ�กัเพิ�ยงต�วัเด�ยวัม่ำ�สม่ำาชิ�กัเพิ�ยงต�วัเด�ยวั
โจทย์� น่�าคิ�ดน่�าคิ�ด
?ส�าหร�บภาษาท�� ส�าหร�บภาษาท�� [[] ] { {}}
เป/นิจร�งหร,อไม่ำ'ท�� ภาษานิ�.เป/นิจร�งหร,อไม่ำ'ท�� ภาษานิ�.จะต(องเป/นิจะต(องเป/นิ
infinite setinfinite set
โจทย์� น่�าคิ�ดน่�าคิ�ด
?ส�าหร�บภาษาท�� ส�าหร�บภาษาท�� L = {x}L = {x}
เม่ำ,�อ เม่ำ,�อ xx **
จ�านิวันิ จ�านิวันิ classclass ข้อง ข้อง IILL เป/นิเท'าใดเป/นิเท'าใด