ภาษา language
DESCRIPTION
1. ภาษา LANGUAGE. LANGUAGE. ภาษาอังกฤษ. หน่วยของภาษา อักขระ letters คำ words ประโยค sentences ย่อหน้า paragraphs เรื่องราว coherent stories. COLLECTION & SEQUENTIAL. How do they do that ?. LANGUAGE. ภาษาคอมพิวเตอร์. หน่วยของภาษาคอมพิวเตอร์ อักขระ letters คำสำคัญ key words - PowerPoint PPT PresentationTRANSCRIPT
11ภาษาภาษา
LANGUAGELANGUAGE
ภาษาอั�งกฤษภาษาอั�งกฤษหน่�วยของภาษาหน่�วยของภาษา
อ�กขระ อ�กขระ letterslettersคำ�า คำ�า wordswordsประโยคำ ประโยคำ sentencessentencesย�อหน่�า ย�อหน่�า paragraphsparagraphsเร��องราว เร��องราว coherent storiescoherent stories
COLLECTION&
SEQUENTIAL
How do they do that ?
LANGUAGE
หน่�วยของภาษาคำอมพิ�วเตอร�หน่�วยของภาษาคำอมพิ�วเตอร� อ�กขระ อ�กขระ lettersletters คำ�าสำ�าคำ�ญ คำ�าสำ�าคำ�ญ keykeywordswords คำ�าสำ��ง คำ�าสำ��ง commandscommands โปรแกรมโปรแกรม programsprograms ระบบ ระบบ systemssystems
Commands can be recognized by certain sequences of Commands can be recognized by certain sequences of words.words.
Language structure is based on explicitly rules.Language structure is based on explicitly rules.
It is very hard to state all the rules for the language
“spoken English”.
ภาษาภาษาคอัมพิ�วเตอัร์�คอัมพิ�วเตอัร์�
LANGUAGE
DefinitionLanguage means simply a set of strings involving symbols from alphabet.
LANGUAGELANGUAGEภาษาภาษา
LANGUAGE
Formal refersexplicitly rules
What sequences of symbols can occur ? No liberties are tolerated. No reference to any “deeper understanding” is required.
the form of the sequences of symbols
not the meaning
ทฤษฎี�ภาษาร์�ปนั�ยทฤษฎี�ภาษาร์�ปนั�ยTHEORY OF FORMAL LANGUAGESTHEORY OF FORMAL LANGUAGES
LANGUAGE
One finite set of fundamental units , called One finite set of fundamental units , called ““alphabetalphabet”, denoted ”, denoted ..
An element of alphabet is called “An element of alphabet is called “charactercharacter”.”. A certain specified set of strings of characters A certain specified set of strings of characters
will be called “will be called “languagelanguage” denoted L.” denoted L. Those strings that are permissible in the Those strings that are permissible in the
language we call “language we call “wordswords”.”. The string without letter is called “The string without letter is called “empty empty
stringstring” or “” or “null stringnull string”, denoted by ”, denoted by .. The language that has no word is denoted by The language that has no word is denoted by
..
specifie
d
นั�ยามและสั�ญล�กษณ์�นั�ยามและสั�ญล�กษณ์�LANGUAGE
Union operationUnion operation ++Different operationDifferent operation AlphabetAlphabet Empty stringEmpty string
LanguageLanguage LL
Empty languageEmpty language
SYMBOLS
LANGUAGE
การน่�ยามหร�อการบรรยายภาษา
ภาษาภาษาGiven an alphabet Given an alphabet = { a b c … z ‘ - }. = { a b c … z ‘ - }.We can now specify a language L asWe can now specify a language L as
{ { all words in a standard dictionaryall words in a standard dictionary }, },named “named “ENGLISH-WORDS”.”.
IMPLICITLY
DEFINING
LANGUAGE
The trick of defining the language L,The trick of defining the language L,
By listing all rules of grammarBy listing all rules of grammar..
This allows us to give a finite description of an This allows us to give a finite description of an infinite language.infinite language.
Consider this sentenceConsider this sentence “I eat three “I eat three Sundays”.Sundays”.
This is grammatically correct.This is grammatically correct.RIDICULOUSLANGUAGE
การน่�ยามหร�อการบรรยายภาษา
ภาษาภาษาINFINITE LANGUAGE DEFINING
LANGUAGE
Let Let = {x} be an alphabet. = {x} be an alphabet.Language L can be defined byLanguage L can be defined by
L = { x xx xxx xxxx … }L = { x xx xxx xxxx … }
L = { xL = { xnn for n = 1 2 3 … }. for n = 1 2 3 … }.Language Language LL22 = { x xxx xxxxx xxxxxxx …} = { x xxx xxxxx xxxxxxx …}
LL22 = { x = { xoddodd } }
LL22 = { x = { x2n-12n-1 for n = 1 2 3 … }. for n = 1 2 3 … }.
การน่�ยามหร�อการบรรยายภาษา
ภาษาภาษาMethod of exhaustion
LANGUAGE
We define the function We define the function length length of a string to be the of a string to be the number of letters in the string.number of letters in the string.For example, if a word For example, if a word aa = xxxx in L, then length( = xxxx in L, then length(aa)=4.)=4.In any language that includes In any language that includes , we have length(, we have length()=0.)=0.
The function reverse is defined by if The function reverse is defined by if aa is a word in L, then is a word in L, then reverse(reverse(aa) is the same string of letters spelled ) is the same string of letters spelled backward, called the backward, called the reverse reverse of of aa..For example, reverse(123)=321.For example, reverse(123)=321.
Remark: The reverse(Remark: The reverse(aa) is not necessary in the language ) is not necessary in the language of of aa..
นั�ยามภาษาภาษาLANGUAGE
We define the function We define the function nnaa((ww)) of a of a ww to be the to be the number of letter number of letter aa in the string in the string ww..
For example, if a word For example, if a word ww = aabbac in L, = aabbac in L,then then nnaa((ww)=3.)=3.
Concatenation Concatenation of two strings means that two strings of two strings means that two strings are written down side by side.are written down side by side.For example, xFor example, xnn concatenated with x concatenated with xmm is x is xn+mn+m
นั�ยามภาษาภาษาLANGUAGE
Language is called Language is called PALINDROMEPALINDROME over the over the alphabet ifalphabet if
Language = { Language = { and all strings x such that and all strings x such that reserve(x)=x }.reserve(x)=x }.
For example, let For example, let ={ a, b }, and={ a, b }, andPALINDROMEPALINDROME={ ={ a b aa bb aaa aba bab bbb …}. a b aa bb aaa aba bab bbb …}.
Remark: Sometimes, we obtain another word in Remark: Sometimes, we obtain another word in PALINDROME PALINDROME when we concatenate two words in when we concatenate two words in PALINDROMEPALINDROME. We shall see the interesting . We shall see the interesting properties of this language later.properties of this language later.
นั�ยามภาษาภาษาLANGUAGE
Consider the languageConsider the languagePALINDROMEPALINDROME={ ={ a b aa bb aaa aba bab bbb …}. a b aa bb aaa aba bab bbb …}.
We usually put words in size order and then listed all We usually put words in size order and then listed all the words of the same length alphabetically. This the words of the same length alphabetically. This order is called order is called lexicographiclexicographic order. order.
นั�ยามภาษาภาษาLANGUAGE
Given an alphabet Given an alphabet , the language that any string of , the language that any string of characters in characters in are in this language is called the are in this language is called the closure closure of the alphabet. It is denoted byof the alphabet. It is denoted by
**..This notation is sometimes known as the This notation is sometimes known as the Kleene starKleene star..
Kleene star can be considered as an operation that Kleene star can be considered as an operation that makes an infinite language. When we say “makes an infinite language. When we say “infinite infinite
languagelanguage”, we mean infinitely many words, each of ”, we mean infinitely many words, each of finite length.finite length.
นั�ยามภาษาภาษาKLEENE CLOSURE
LANGUAGE
More general,More general,
if S is a set of words, then by S* we mean the set if S is a set of words, then by S* we mean the set of all finite strings formed by concatenating words of all finite strings formed by concatenating words from S and from S*.from S and from S*.
Example:Example:If S = { a ab }thenIf S = { a ab }then
S* =S* = { { and any word composed of factors of a and ab }. and any word composed of factors of a and ab }.
{ { and all strings of a and b except strings with and all strings of a and b except strings with double b }.double b }.
{ { a aa ab aaa aab aba aaaa aaab aaba … }. a aa ab aaa aab aba aaaa aaab aaba … }.
นั�ยามภาษาภาษาKLEENE CLOSURE
LANGUAGE
Example:Example:If S = { a ab }thenIf S = { a ab }then
S* =S* = { { and any word composed of factors of a and ab }. and any word composed of factors of a and ab }.
{ { and all strings of a and b except strings with double and all strings of a and b except strings with double b }.b }.
{ { a aa ab aaa aab aba aaaa aaab aaba … }. a aa ab aaa aab aba aaaa aaab aaba … }.
To prove that a certain word is in the closure language S* , we must show how it can be written as a concatenation of words from the base set S.
Example: abaaba can be factored as (ab)(a)(ab)(a) and
it is unique.
นั�ยามภาษาภาษาKLEENE CLOSURE
LANGUAGE
Example:Example:
If S = { xx xxxxx }thenIf S = { xx xxxxx }then
S* =S* = { { xx xxxx xxxxx xxxxxx xxxxxxx xxxxxxxx xx xxxx xxxxx xxxxxx xxxxxxx xxxxxxxx … }.… }.
{ { and xx and x and xx and xnn for n = 4 5 6 7 … }. for n = 4 5 6 7 … }.How can we prove this statement ?
Hence: proof by constructive algorithm
(showing how to create it).
นั�ยามภาษาภาษาKLEENE CLOSURE
LANGUAGE
Example:Example:
If S = { a b ab } and T = { a b ba }, then S* = T* = { a If S = { a b ab } and T = { a b ba }, then S* = T* = { a b }*.b }*.
Proof:Proof: It is clear that { a b }*It is clear that { a b }* S* and { a b }* S* and { a b }*T*.T*.
We have to show that S* and T* We have to show that S* and T* { a b }*. { a b }*.
For x For x S*, in the case that x is composed of ab. S*, in the case that x is composed of ab.
Replace ab in x by a, b which are in { a b }*.Replace ab in x by a, b which are in { a b }*.
Then S*Then S* { a b }*. { a b }*.
The proof of T*The proof of T* { a b }* is similarity. { a b }* is similarity.QEDQED
นั�ยามภาษาภาษาKLEENE CLOSURE
LANGUAGE
Given an alphabet Given an alphabet , the language that any , the language that any string string (not zero)(not zero) of characters in of characters in are in are in this language is called the this language is called the positive closurepositive closure of the alphabet. It is denoted byof the alphabet. It is denoted by
++..
Example: Let Example: Let ={ ab }.={ ab }.Then Then ++ = { ab abab ababab … }. = { ab abab ababab … }.
นั�ยามภาษาภาษาPOSITIVE CLOSURE
LANGUAGE
Given an alphabet Given an alphabet ={ aa bbb }. Then ={ aa bbb }. Then * is the set * is the set of all strings where a’s occur in even clumps and of all strings where a’s occur in even clumps and b’s in groups of 3, 6, 9…. Some words in b’s in groups of 3, 6, 9…. Some words in * are* are
bbb aabbbaaaa bbbaabbb aabbbaaaa bbbaaIf we concatenate these three elements of If we concatenate these three elements of *, we get *, we get
one big word in one big word in ****,, which is again in which is again in *.*.bbbaabbbaaaabbbaa = (bbb)(aa)(bbb)(aa)(aa)(bbb)bbbaabbbaaaabbbaa = (bbb)(aa)(bbb)(aa)(aa)(bbb)
(aa)(aa)
Note : Note : ** means (** means (*)*.*)*.
นั�ยามภาษาภาษาTRIVIAL REMARK
LANGUAGE
TheoremTheorem
For any set S of strings, we have S*= S**.For any set S of strings, we have S*= S**.
Proof:Proof: Every words in S** is made up of factors from S*.Every words in S** is made up of factors from S*.
Every words in S* is made up of factors from S.Every words in S* is made up of factors from S.
Therefore every words in S** is made up of factors Therefore every words in S** is made up of factors from S.from S.
We can write thisWe can write this S**S** S*. S*.
In general, it is true that S In general, it is true that S S*. So S* S*. So S* S**. S**.
Then S*= S**.Then S*= S**. QEDQED
นั�ยามภาษาภาษาTHEOREM
LANGUAGE
โจทย� นั"าค�ดนั"าค�ดใให� ห� LL เป#น่ภาษาที่%�น่�ยามบน่ เป#น่ภาษาที่%�น่�ยามบน่ ={0,1} ={0,1}
จงอธิ�บายจงอธิ�บาย คำวามสำ�มพิ�น่ธิ�ของคำวามสำ�มพิ�น่ธิ�ของ L*L*++
LL++** ?
22RECURSIVELY DEFINING LANGUAGERECURSIVELY DEFINING LANGUAGE
การบรรยายภาษาแบบวน่ซ้ำ�)าการบรรยายภาษาแบบวน่ซ้ำ�)า
น่�ยายของภาษาการบรรยายแบบวน่การบรรยายแบบวน่ซ้ำ�)าซ้ำ�)าEVEN languageEVEN languageEVEN is the set of all positive whole numbers divisible by EVEN is the set of all positive whole numbers divisible by
2.2.EVEN is the set of all 2n where n = 1 2 3 4 …EVEN is the set of all 2n where n = 1 2 3 4 …
Another way we might try this:Another way we might try this:The set is defined by these three rules:The set is defined by these three rules:
Rule1:Rule1: 2 is in EVEN. 2 is in EVEN.Rule2:Rule2: if x is in EVEN, then so is x+2. if x is in EVEN, then so is x+2.
Rule3:Rule3: The only elements in the set EVEN are those that The only elements in the set EVEN are those thatcan be produced from the two rules abovecan be produced from the two rules above..
The last rule above is completely redundant.
RECURSIVELY DEFINING LANGUAGE
EVEN languageEVEN languageThe set is defined by these three rules:The set is defined by these three rules:
Rule1:Rule1: 2 is in EVEN. 2 is in EVEN.Rule2:Rule2: if x is in EVEN, then so is x+2. if x is in EVEN, then so is x+2.
Rule3:Rule3: The only elements in the set EVEN are those that The only elements in the set EVEN are those that
can be produced from the two rules above.can be produced from the two rules above. PROBLEM: Show that 10 is in this language.PROBLEM: Show that 10 is in this language.
By Rule1, 2 is in EVEN.By Rule1, 2 is in EVEN.By Rule2, 2+2=4 is in EVEN.By Rule2, 2+2=4 is in EVEN.By Rule2, 4+2=6 is in EVEN.By Rule2, 4+2=6 is in EVEN.By Rule2, 6+2=8 is in EVEN.By Rule2, 6+2=8 is in EVEN.By Rule2, 8+2=10 is in EVEN.By Rule2, 8+2=10 is in EVEN.
PRETTY HORRIBLE !PRETTY HORRIBLE !
น่�ยายของภาษาการบรรยายแบบวน่การบรรยายแบบวน่ซ้ำ�)าซ้ำ�)า
1000000
RECURSIVELY DEFINING LANGUAGE
EVEN languageEVEN languageThe set is defined by these three rules:The set is defined by these three rules:
Rule1:Rule1: 2 is in EVEN. 2 is in EVEN.Rule2:Rule2: if x,y are in EVEN, then so is x+y. if x,y are in EVEN, then so is x+y.
Rule3:Rule3: The only elements in the set EVEN are those that The only elements in the set EVEN are those that
can be produced from the two rules above.can be produced from the two rules above. PROBLEM: Show that 10 is in this language.PROBLEM: Show that 10 is in this language.
By Rule1, 2 is in EVEN.By Rule1, 2 is in EVEN.By Rule2, 2+2=4 is in EVEN.By Rule2, 2+2=4 is in EVEN.By Rule2, 4+4=8 is in EVEN.By Rule2, 4+4=8 is in EVEN.By Rule2, 8+2=10 is in EVEN.By Rule2, 8+2=10 is in EVEN.
DECIDEDLY HARD
น่�ยายของภาษาการบรรยายแบบวน่การบรรยายแบบวน่ซ้ำ�)าซ้ำ�)า
RECURSIVELY DEFINING LANGUAGE
POSITIVE languagePOSITIVE languageThe set is defined by these three rules:The set is defined by these three rules:
Rule1:Rule1: 1 is in POSITIVE. 1 is in POSITIVE.Rule2:Rule2: if x,y are in POSITIVE, then so is x+y, x-y, x if x,y are in POSITIVE, then so is x+y, x-y, xy y
and x/y where y is not zero.and x/y where y is not zero.Rule3:Rule3: The only elements in the set POSITIVE are The only elements in the set POSITIVE are
those thatthose thatcan be produced from the two rules above.can be produced from the two rules above.
PROBLEM: What is POSITIVE language ?PROBLEM: What is POSITIVE language ?
น่�ยายของภาษาการบรรยายแบบวน่การบรรยายแบบวน่ซ้ำ�)าซ้ำ�)า
RECURSIVELY DEFINING LANGUAGE
POLYNOMIAL languagePOLYNOMIAL languageThe set is defined by these four rules:The set is defined by these four rules:Rule1:Rule1: Any number is in POLYNOMIAL Any number is in POLYNOMIAL
Rule2:Rule2: Any variable x is in POLYNOMIAL. Any variable x is in POLYNOMIAL.Rule3:Rule3: if x,y are in POLYNOMIAL, if x,y are in POLYNOMIAL,then so is x+y, x-y, xthen so is x+y, x-y, xy and (x).y and (x).
Rule4: The only elements in the set POLYNOMIAL are those thatRule4: The only elements in the set POLYNOMIAL are those thatcan be produced from the three rules above.can be produced from the three rules above.
PROBLEM: Show that PROBLEM: Show that 3x3x22+2x-5 +2x-5 is in POLYNOMIAL.is in POLYNOMIAL.Proof:Proof:
Rule1:Rule1: 2, 3, 5 are in POLYNOMIAL, 2, 3, 5 are in POLYNOMIAL, Rule2:Rule2: x is in x is in POLYNOMIAL,POLYNOMIAL,Rule3:Rule3: 3x, 2x are in POLYNOMIAL, 3x, 2x are in POLYNOMIAL, Rule3:Rule3: 3xx is in 3xx is in POLYNOMIAL,POLYNOMIAL,Rule3:Rule3: 3xxx+2x, 3x 3xxx+2x, 3x22+2x-5 are in POLYNOMIAL.+2x-5 are in POLYNOMIAL. QED.QED.
น่�ยายของภาษาการบรรยายแบบวน่การบรรยายแบบวน่ซ้ำ�)าซ้ำ�)า
RECURSIVELY DEFINING LANGUAGE
น่�ยายของภาษาARITHMETIC EXPRESSIONS
Language:Language:Let Let be an alphabet for AE language. be an alphabet for AE language. = { 0 1 2 3 4 5 6 7 8 9 + - * / ( ) }.= { 0 1 2 3 4 5 6 7 8 9 + - * / ( ) }.
Define rules for this language.Define rules for this language.Problems:Problems:
Show that the language does not contain Show that the language does not contain substring //.substring //.
Show that ((3+4)-(2*6))/5 is in this Show that ((3+4)-(2*6))/5 is in this language.language.
การบรรยายแบบวน่การบรรยายแบบวน่ซ้ำ�)าซ้ำ�)า
RECURSIVELY DEFINING LANGUAGE
การบรรยายภาษา
ข้%อัข้%อัสั�งเกสั�งเก
ตตLanguages can be defined byLanguages can be defined by
LL11={ x={ xnn for n = 1 2 3 … } for n = 1 2 3 … } LL22={ x={ xnn for n = 1 3 5 7 … } for n = 1 3 5 7 … } LL33={ x={ xnn for n = 1 4 9 16 … } for n = 1 4 9 16 … } LL44={ x={ xnn for n = 3 4 8 22 … }. for n = 3 4 8 22 … }.
More precision and less guesswork are required.
RECURSIVELY DEFINING LANGUAGE
33REGULAR EXPRESSIONREGULAR EXPRESSION
การบรรยายแบบการบรรยายแบบสำม��าเสำมอสำม��าเสำมอ
Kleene star
การบรรยายภาษาแบบการบรรยายภาษาแบบสำม��าเสำมอสำม��าเสำมอ
Definition:Definition:The simple expression x* will be used to indicate The simple expression x* will be used to indicate some sequence of x’s (may be none at all).some sequence of x’s (may be none at all).We also define xWe also define x00 = = ..
The star is as an unknown power or undetermined power. This notation can be used to help us define languages by writing
L = language(x*)
where L = { and xn for n = 1 2 3 … }.
REGULAR EXPRESSION
ต�วอัย"างLL11 = language(ab*) = language(ab*)
LL11 = { a ab abb abbb abbbb abbbbb abbbbbb … } = { a ab abb abbb abbbb abbbbb abbbbbb … }
LL22 = language(a*ba*) = language(a*ba*)
LL22 = { b ab ba aab aba baa aaab aaba abaa baaa … } = { b ab ba aab aba baa aaab aaba abaa baaa … }
LL33 = language(a*b*) = language(a*b*)
LL33 = { = { a b aa ab bb aaa aab abb bbb aaaa aaab aabb a b aa ab bb aaa aab abb bbb aaaa aaab aabb … }… }
LL44 = language((ab)*) = language((ab)*)
LL44 = { = { ab abab ababab abababab ababababab … } ab abab ababab abababab ababababab … }
LL55 = language(xx*) = language(xx*)
LL55 = { x xx xxx xxxx xxxxx xxxxxx … } = = { x xx xxx xxxx xxxxx xxxxxx … } = language(xlanguage(x++))
การบรรยายภาษาแบบการบรรยายภาษาแบบสำม��าเสำมอสำม��าเสำมอ
REGULAR EXPRESSION
การ์บวก (union)
Definition:Definition:The plus expression The plus expression x + yx + y where x and y are where x and y are string of characters from an alphabet, we mean string of characters from an alphabet, we mean ““either x or y, but not botheither x or y, but not both”.”.
Example:L = language((a+b)c*)
L = { a b ac bc acc bcc accc bccc … }.
การบรรยายภาษาแบบการบรรยายภาษาแบบสำม��าเสำมอสำม��าเสำมอ
REGULAR EXPRESSION
Exercise:Exercise:L = language(a*+(a+bb)*c*+d)L = language(a*+(a+bb)*c*+d)
Is Is in this language ? in this language ? Find words with length 1, 2, 3 and 4.Find words with length 1, 2, 3 and 4. Compare L with language(a*c*+Compare L with language(a*c*+
(bb)*c*+d).(bb)*c*+d).
การบรรยายภาษาแบบการบรรยายภาษาแบบสำม��าเสำมอสำม��าเสำมอ
REGULAR EXPRESSION
Finite languageFinite language
The language L whereThe language L where
L = { aaa aab aba abb baa bab bba bbb }L = { aaa aab aba abb baa bab bba bbb }
can be expressed by can be expressed by L = language((a+b)L = language((a+b)33) or) or
L = language((a+b)(a+b)L = language((a+b)(a+b)(a+b)).(a+b)).
การบรรยายภาษาแบบการบรรยายภาษาแบบสำม��าเสำมอสำม��าเสำมอ
REGULAR EXPRESSION
Definition:Definition:The set of The set of regular expressionsregular expressions is defined by the is defined by the following rules:following rules:Rule1:Rule1: Every element of alphabet Every element of alphabet is a regular is a regular
expression.expression.Rule2:Rule2: is a regular expression. is a regular expression.Rule3:Rule3: For every regular expressions For every regular expressions rr and and ss,,
then so are:then so are:(r) rs r+s r*(r) rs r+s r*
Rule4:Rule4: Nothing else is not a regular expression.Nothing else is not a regular expression.
REGULAR EXPRESSIONS
การบรรยายภาษาแบบการบรรยายภาษาแบบสำม��าเสำมอสำม��าเสำมอ
REGULAR EXPRESSION
REGULAR EXPRESSIONS
Example:Example:Given a regular expression Given a regular expression (a+b)*a(a+b)*+b(a+b)*(a+b)*a(a+b)*+b(a+b)*
This regular expression can be written This regular expression can be written more simple expression, as follow:more simple expression, as follow:
(a+b)(a+b)*.(a+b)(a+b)*.
การบรรยายภาษาแบบการบรรยายภาษาแบบสำม��าเสำมอสำม��าเสำมอ
REGULAR EXPRESSION
REGULAR EXPRESSIONS
Finite & Positive closure:Finite & Positive closure:Is (a+b)Is (a+b)44 a regular expression ? a regular expression ?
This can be accepted to be a regular expression, This can be accepted to be a regular expression, since it equals to (a+b)(a+b)(a+b)(a+b) which is a since it equals to (a+b)(a+b)(a+b)(a+b) which is a regular expression.regular expression.
Is (a+c)Is (a+c)++ a regular expression ? a regular expression ?
This is also be accepted to be a regular expression This is also be accepted to be a regular expression since it represents a regular expression (a+c)since it represents a regular expression (a+c)(a+c)*.(a+c)*.
การบรรยายภาษาแบบการบรรยายภาษาแบบสำม��าเสำมอสำม��าเสำมอ
REGULAR EXPRESSION
REGULAR EXPRESSIONS
ท'าอัย"างไร์Define the set A by a regular expression.Define the set A by a regular expression.
A = A = { { b ab bb b ab bbaba abb bbbaba abb bbbabaa abab abbb bbbbabaa abab abbb bbbbabaaa abaab ababb abbbb bbbbb abaaa abaab ababb abbbb bbbbb
… }.… }.The regular expression isThe regular expression is (aba*)*b*(aba*)*b*
การบรรยายภาษาแบบการบรรยายภาษาแบบสำม��าเสำมอสำม��าเสำมอ
REGULAR EXPRESSION
REGULAR EXPRESSIONS
แบบฝึ*กหั�ดGiven a regular expressionGiven a regular expression
(a+b)*ab(a+b)*+E(a+b)*ab(a+b)*+Ewhere E is unknown expression.where E is unknown expression.Find E if this expression equals Find E if this expression equals (a+b)*(a+b)*and E and E (a+b)*ab(a+b)* = (a+b)*ab(a+b)* =
The regular expression E isThe regular expression E is b*a*.b*a*.
การบรรยายภาษาแบบการบรรยายภาษาแบบสำม��าเสำมอสำม��าเสำมอ
REGULAR EXPRESSION
REGULAR EXPRESSIONS
Definition:Definition:Let S and T be sets of strings of letters. The Let S and T be sets of strings of letters. The product setproduct set of S and T is the set of all of S and T is the set of all combinations of a string from S concatenated with combinations of a string from S concatenated with a string from T in that order.a string from T in that order.
ST = { uv : u ST = { uv : u S and v S and v T } T }
Example:Example: S = { a bb aba }S = { a bb aba }
T = { a ab }T = { a ab }
thenthen ST = { aa aab bba bbab abaa abaab }.ST = { aa aab bba bbab abaa abaab }.
การบรรยายภาษาแบบการบรรยายภาษาแบบสำม��าเสำมอสำม��าเสำมอ
REGULAR EXPRESSION
REGULAR EXPRESSIONS
Example:Example:P = { P = { aa b } and Q = { aa b } and Q = { ba } ba }
Then PQ = { Then PQ = { aa b ba aaba bba }. aa b ba aaba bba }.
การบรรยายภาษาแบบการบรรยายภาษาแบบสำม��าเสำมอสำม��าเสำมอ
REGULAR EXPRESSION
Definition:Definition:A language L is called a A language L is called a language language associatedassociated with regular expression r if with regular expression r if
L = language(r).L = language(r).We also haveWe also have
LL11LL22 = language(r = language(r11rr22))
LL11+L+L22 = language(r = language(r11+r+r22))
LL11* = language(r*).* = language(r*).
REGULAR EXPRESSIONS
การบรรยายภาษาแบบการบรรยายภาษาแบบสำม��าเสำมอสำม��าเสำมอ
REGULAR EXPRESSION
ที่ฤษฎี%บที่ที่ฤษฎี%บที่If L is a finite language (only finitely many If L is a finite language (only finitely many words), then L can be defined by a regular words), then L can be defined by a regular expression. In other words, all finite expression. In other words, all finite languages are regular.languages are regular.
REGULAR EXPRESSIONS
การบรรยายภาษาแบบการบรรยายภาษาแบบสำม��าเสำมอสำม��าเสำมอ
REGULAR EXPRESSION
What strings contain in the language?What strings contain in the language? Given (a+b)*(aa+bb)(a+b)*+(Given (a+b)*(aa+bb)(a+b)*+(+b)(ab)*(+b)(ab)*(+a)+a) Consider the regular (a+b)*(aa+bb)(a+b)*, Consider the regular (a+b)*(aa+bb)(a+b)*,
strings that contain a double letter.strings that contain a double letter. { { a b ab ba aba bab abab baba ... } is the set a b ab ba aba bab abab baba ... } is the set
of all strings that do not contain a double letter.of all strings that do not contain a double letter. ((+b)(ab)*(+b)(ab)*(+a) defines all strings without a +a) defines all strings without a
double letter.double letter. This language is This language is (a+b)*.(a+b)*.
REGULAR EXPRESSIONS
การบรรยายภาษาแบบการบรรยายภาษาแบบสำม��าเสำมอสำม��าเสำมอ
REGULAR EXPRESSION
Consider a regular expressionConsider a regular expression(aa+bb+(ab+ba)(aa+bb)*(ab+ba))*.(aa+bb+(ab+ba)(aa+bb)*(ab+ba))*.This represents the collection of all words that This represents the collection of all words that
are made up of three type:are made up of three type:type1type1 aaaatype2type2 bbbbtype3type3 (ab+ba)(aa+bb)*(ab+ba)(ab+ba)(aa+bb)*(ab+ba)
Every words contain an even number of a and Every words contain an even number of a and even number of b.even number of b.
EVEN-EVENLANGUAGE
REGULAR EXPRESSIONS
การบรรยายภาษาแบบการบรรยายภาษาแบบสำม��าเสำมอสำม��าเสำมอ
REGULAR EXPRESSION
โจทย� นั"าค�ดนั"าค�ดจจงหาภาษา งหาภาษา LL ที่%�น่�ยามบน่ ที่%�น่�ยามบน่ ={0,1} ={0,1} ที่%�ที่%�สำอดคำล้�องก�บสำอดคำล้�องก�บ
L L ไม�เป#น่ ไม�เป#น่ {{}} L L ไม�เป#น่ ไม�เป#น่ **
โดยโดยที่%� ที่%� L = L*L = L* ?
โจทย� นั"าค�ดนั"าค�ดก�าก�าหน่ดให�ภาษา หน่ดให�ภาษา L L แล้ะ แล้ะ SS น่�ยามบน่ น่�ยามบน่ ={0,1} ={0,1} ที่%�สำอดคำล้�องก�บที่%�สำอดคำล้�องก�บ
LS = SLLS = SL L L ไม�เป#น่ ไม�เป#น่ subset subset ของ ของ SS S S ไม�เป#น่ ไม�เป#น่ subset subset ของ ของ LL ที่�)ง ที่�)ง L L แล้ะ แล้ะ S S ไม�เป#น่ ไม�เป#น่ {{}}?
โจทย� นั"าค�ดนั"าค�ดก�าก�าหน่ดให�ภาษา หน่ดให�ภาษา L L แล้ะ แล้ะ SS น่�ยามบน่ น่�ยามบน่ ={0,1} ={0,1} ที่%�สำอดคำล้�องก�บที่%�สำอดคำล้�องก�บ
LS = SLLS = SL L L เป#น่ เป#น่ proper nonempty proper nonempty
subset subset ของ ของ SS L L ไม�เป#น่ ไม�เป#น่ {{}} ?