Download presentation
Presentation is loading. Please wait.
Published byMarshall Chandler Modified over 8 years ago
1
Lecture #2 Advanced Theory of Computation
2
Languages & Grammar Before discussing languages & grammar let us deal with some related issues. Alphabet: is defined as a nonempty finite set of symbols or letters such as {a 1, a 2, …, a k }. Particularly the alphabet for theory of computation is mostly the binary alphabet {0, 1}. Set of alphabet represented by
3
Languages & Grammar A string (word or sentence): is defied as a finite sequence of symbols over the set of alphabet (∑), e.g. aaabbbabbb is string over ∑ = {a, b}. A string might be represent by w. A string may have no symbol at all, in this case it is called the empty string / null string and denoted by
4
Note: Some times string (word/sentence) can be represented as function. e.g. A string x = x 0 x 1 x 2 x 3 … x n, which can be viewed as function as: x : [n] | x(k) = x k. where n is the length of the string x, which denoted by |x|, e.g. |aabbaab| = 7
5
Operations on strings For an alphabet Σ, given any two strings u: [m] → Σ and v: [n] → Σ, the concatenation u ・ v (also written as uv) of u and v is the string uv: [m + n] → Σ, defined such that: In particular
6
Formal Languages Formal vs. Natural Languages Natural Languages: used by human to communicate. e.g. Arabic, English, … syntax is very complicated not completely specified
7
Formal Languages Formal vs. Natural Languages Formal Language: specified by a well-defined sets of grammatical rules e.g. programming languages syntax completely defined by given grammar.
8
Why study Formal Languages? Programming languages are formal. very useful for pattern matching. Important for research in natural language processing (NLP) with computers. Closely tied to study of abstract machines.
9
Formal Languages Let be any finite set of symbols (possibly none), called an alphabet. A word (string) over is any fine sequence of letters from. A formal language is simply a set of strings
10
Formal Languages defined as the set of all possible words over, including the empty word (denoted by ). Example Let, then
11
A language over is defined as strings over i.e. a subset of Examples: ∑ = {a, b}
12
Example Let Then The language is a finite language on. Note: Language can be infinite, and the most interesting languages are infinite.
13
New language can be constructed using any of the set operations. As an example the union of tow languages over, is also a language over. Having {as, so} and {if, soon, possible} as tow languages over the concatenation of the tow languages give another language over as follows. {as, so} {if, soon, possible} = {asif, assoon, aspossible, soif, sosoon, sopossible}.
14
Regular Expression & Language Definition: A regular expression over, that corresponding to a language, can be defined as follows. is a regular expression, corresponding to the empty language.
15
Regular Expression & Language For each symbol a is a regular expression corresponding to the language {a}. is a regular expression, corresponding to the empty language., ε and a are called primitive regular expressions.
16
corresponding to L r L s corresponding to A language over is a regular language if there is some regular expression over corresponding to it. For any regular expression r and s over, corresponding to the languages L r and L s, respectively, each of the following are regular expression over, corresponding to the language indicated.
17
Examples of regular expression over All words over MeaningExpression All words over beginning with 0 followed only by 1’s. All words over containing exactly two 0’s. All words over containing two consecutive 0’s or two consecutive 1s.
18
Meaning Expression All words over containing an even number of 0’s an even number of 1’s. All words over in which every 1 immediately followed by at least tow 0’s.
19
Meaning Expression All strings containing only 0’s, 1’s, that begin with b and ending with a 2. All strings that starting with any number of 1’s followed by 001, followed by any number of 0’s.
20
Formal Grammar Formal definition where, A generative grammar, which firstly proposed by Noam Chomsky in 1950s, considered as a grammar G that defined as a quadruple.
21
is a finite set of objects called variables. is a finite set of objects called terminal symbols. is a special symbol called start variable. is a finite set of productions. It is assumed that and are nonempty and disjoint
22
Definition (L(G)) Let be a grammar. Then the set is the language generated by.
23
Example Consider a grammar G that defined as where, V = {S, B}T = {a, b, c} P consists of the following production rule S aBSc S abc Ba aBBb bb
24
L(G) may be derived to be consisted of the following strings: L(G) = {abc, aabbcc, aaabbbccc, …} Therefore L(G) can be represented as L(G) = {a n b n c n | n>0} L(G) = {w {a, b, c} * | n a (w) = n b (w) = n c (w)}
25
Example Consider a grammar G that defined as where, V = {S, A, B}T = {0, 1} P consists of the following production rule S A|B A 0A1|εB 0B1|ε L(G) = L(A) U L(B) = {0 n 1 n : n ≥ 0} U {1 n 0 n : n ≥ 0}
26
Example Consider a grammar G that defined as where, V = {S, X}T = {0, 1} P consists of the following production rule S 0S|0X X 0X1|ε L(G) = {0 m 1 n :m > n}
27
Representation of Language using Graphs Transition Graph over is a finite directed graph in which every arrow (edge) is labeled by some word (possibly the empty word ( )). There is a least one vertex, labeled by a ( ) sign (such vertices are called initial vertices), and a (possibly empty set) of vertices, labeled by a ( ) sign (called the final vertices). A vertex can be both initial and final.
28
Example Consider the following transition graphs over
29
All words over beginning with a followed by All words over containing two consecutive ( ) or two consecutive ( )
30
All words over containing an even number of ( ) and even number of ( ) All words over either starting with ( ) or containing ( ).
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.