Download presentation
Presentation is loading. Please wait.
Published byBuck Cannon Modified over 9 years ago
1
::ICS 804:: Theory of Computation - Ibrahim Otieno - iotieno@uonbi.ac.ke +254-0722-429297 SCI/ICT Building Rm. G15
2
Course Outline Mathematical Preliminaries Turing Machines Recursion Theory Markov Algorithms Register Machines Regular Languages and finite-state automata Aspects of Computability
3
Last week: Register Machines Register machines Register machines and formal languages Model-independent characterization of computational feasibility
4
Course Outline Mathematical Preliminaries Turing Machines ◦ Additional Varieties of Turing Machines Recursion Theory Markov Algorithms Register Machines Regular Languages and finite-state automata Aspects of Computability
5
Regular Languages and finite-state automata Regular Expressions and regular languages Deterministic FSA Non-deterministic FSA Finite-state automata with epsilon moves Generative grammars Context-free, Context-sensitive languages Chomsky Hierarchy
6
Regular Expressions and Regular Languages
7
Characterizing formal languages Plain words: the language of all and only those words over ={a,b} of length 2 (aa,bb,ab,ba,bb) Set abstraction: {w|w * and |w| = 2} New way: regular expressions denote languages
8
Regular Expressions Denote Languages a* denotes language {a n |n 0} (a).(b) or just ab denotes unit language {ab} a*b* denotes {a n b m |n,m 0} a 2 b 3 denotes {aabbb} a n not regular expression a + bb denotes {a n bb|n 1} a ? bb denotes {a n bb| 0 n 1} a|b denotes {a,b}
9
Exercise a* denotes language {a n |n 0} (a).(b) or just ab denotes unit language {ab} a*b* denotes {a n b m |n, m 0} a 2 b 3 denotes {aabbb} a n not regular expression a + bb denotes {a n bb|n 1} a ? bb denotes {a n bb| 0 n 1} a|b denotes {a,b} What does ((a.b)*)|((b.a)*) mean? Give a few examples
10
Exercise a* denotes language {a n |n 0} (a).(b) or just ab denotes unit language {ab} a*b* denotes {a n b m |n, m 0} a 2 b 3 denotes {aabbb} a n not regular expression a + bb denotes {a n bb|n 1} a ? bb denotes {a n bb| 0 n 1} a|b denotes {a,b} What does ((a.b)*)|((b.a)*) mean? Give a few examples The language containing all and only even-length words consisting of alternating a’s and b’s {,ab,ba,abab,baba,…}
11
Kleene-Closure Operator (recap) Symbol *: certain unary operation on languages Given language L L* = def {w| for some n 0, w is the concatenation of n words of L} L*: is the result of concatenating 0 or more words of L
12
Language forming operations (recap) Binary concatenation operation:. L 1.L 2 = def. {w 1 w 2 |w 1 L 1 & w 2 L 2 } The language that results from taking a word from L 1 and appending to it a word from L 2
13
Definition - Regular Expression (i) is regular expression (over ) and denotes language (ii) is regular expression (over ) and denotes language { } (iii) If s is in * then s itself is a regular expression and denotes language {s} (iv) Suppose s and r are regular expressions that denote languages L r and L s, then (a) (r|s) is a regular expression that denotes L r L s (b) (r.s) is a regular expression that denotes L r.L s (c) (r*) is a regular expression that denotes (L r )* (v) No expression is a regular expression unless it is obtainable from (i) – (iv)
14
Definition What about (r+) What about (r?)
15
Definition What about (r+) = ((r*).r) What about (r?) = ( |r)
16
Notation Usually forget about parentheses: (ab)= ab (a|b|c): 3-word language {a,b,c} parentheses > superscript > concatenation > alternation ab* = a(b*) (ab)* a|ba= (a|(b.a)) ((a|b).a)
17
Regular Languages Let L be a language over alphabet , i.e., L *. Then L is said to be a regular language if L is denoted by some regular expression over Let be a finite alphabet and L 1 and L 2 regular languages over . Then L 1 L 2, L 1.L 2, and L 1 * are also regular languages
18
Remarks if is a finite alphabet and w is any word over *. Then unit language {w} is regular. if is a finite alphabet. Then any finite language over is regular.
19
Deterministic Finite State Automata
20
Finite State Automata New model of computation: analysis of the kind of computation that requires a fixed (finite) amount of memory for arbitrary input Also called finite-state machines
21
Deterministic Finite-State Automata = {a,b} Vertices and arcs Labels of arcs are members of No tapes, but input Input: (possibly empty) word over e.g. abb
22
Deterministic Finite-State Automata Accepting configuration: FSA halts in state q 1 The FSA accepts word abb e.g. aba q 2 : trap state L = {ab n |n0}
23
Determinism For each state/symbol pair, FSA M has exactly one instruction FSA M has at least one instruction. This makes M fully defined Determinism means that, within any state diagram for FSA, the path labeled by given word w is unique: for word w *, there is exactly one path starting at q 0 and labeled by w
24
Exercise Which regular language is accepted by this FSA? What are the accepting states? Is an accepted word? What is the trap state? Is the trap state a sink? Is the language finite?
25
Exercise Which regular language is accepted by this FSA? a(a|b)a ? What are the accepting states? q 2 and q 3 Is an accepted word? no What is the trap state? q 4 Is the language finite? yes
26
Exercise Which regular language is accepted by this FSA? What are the accepting states? Is an accepted word? What is the trap state? Is the language finite?
27
Exercise Which regular language is accepted by this FSA? (aba)* What are the accepting states? q 0 Is an accepted word? yes What is the trap state? q 3 Is the language finite? no
28
Alternate description M(q 0,a) = q 1 M(q 0,b) = q 2 M(q 1,b) = q 1 M(q 1,a) = q 2 M(q 2,a) = q 2 M(q 2,b) = q 2
29
Formal Definition A deterministic FSA is a quintuple ,Q,q init,F, ◦ is the input alphabet ◦ Q is a finite, nonempty set of states ◦ q init Q is the initial state or start state ◦ F Q is a (possibly empty) set of accepting or terminal states ◦ : Q Q transition function (total and single valued)
30
Word Acceptance A deterministic finite-state automaton M accepts word w * if there is a unique path starting at q init and labeled by w that leads to some member of F
31
Language Acceptance The language accepted by M is the set of all and only those words over that are accepted by M L(M) for the language accepted by M. FSAs are language acceptors only
32
Nondeterministic Finite State Automata
33
Non-determinism Cf. Turing Machines Existence of alternative instructions for a given state/symbol pair
34
A Nondeterministic Machine q0 q1 q2 a b b a a b L = (ab)* L = (ab)* {a} = (ab)*|a
35
Non-determinism Nondeterministic FSA are usually easier to design but run the risk of accepting unintended words : Q Q is a transition mapping Assumed to be total but permitted to be multi-valued Cf. difference between function and mapping!
36
Formal Definition A nondeterministic FSA is a quintuple ,Q, q init,F, ◦ is the input alphabet ◦ Q is a finite, nonempty set of states ◦ q init Q is the initial state or start state ◦ F Q is a (possibly empty) set of accepting or terminal states ◦ : Q Q transition mapping (total and possibly multi-valued)
37
Word Acceptance Word w * is accepted by FSA M provided there exists some path, labeled by w, in the state diagram of M leading from q init to a terminal state Cf. deterministic definition of word acceptance: unique path
38
Language Acceptance The language accepted by a nondeterministic FSA is the set of words accepted by M.
39
Nondeterminism determinism Nondeterministic FSA are easier to design For every nondeterministic FSA, there exists an equivalent deterministic FSA We can automatically convert the nondeterministic FSA to an equivalent deterministic FSA through subset construction
40
Finite-state automata with epsilon moves
41
Epsilon moves Executing arcs labeled do not advance input -arcs may or may not introduce nondeterminism
42
Example (a*b*c*) 3 2 10 a a a a b b b b c c c c
43
Equivalence Result Let M be FSA with -moves. Then there exists a FSA M´ with no -moves such that L(M) = L(M´)
44
Non-determinism -moves do not necessarily imply nondeterminism 2 1 0 a
45
Regular languages The family of regular languages is identical to the family of FSA-acceptable languages !!!!!!!!!!!!!!!!!
46
Generative Grammars
47
Alternative characterization of the family of (regular) languages Example with just 2 productions (1) S aSb (2) S Generates all words of form a n b n for n 0 e.g.aaabbb S aSb(1) aaSbb(1) aaaSbbb(1) aaa bbb(2)
48
Definition empty productions grammar terminals (usually lowercase) terminal alphabet grammar non-terminals (usually uppercase) Non-terminal alphabet start symbol S in production set
49
Second Example (1)S aaXcc (2)X aXc (3)X b Generates all words of form a n bc n for n 2 e.g. aaaabcccc S aaXcc (1) aaaXccc (2) aaaaXcccc (2) aaaabcccc (3)
50
Third Example (1)S aS´bc (2)S (3)S´ aS´bC (4)S´ (5)Cb bC (6)Cc cc Generates language {a n b n c n |n 0} e.g. aaabbbccc S aS’bc(1) aaS’bCbc(2) aaaS’bCbCbc(2) aaabCbCbc(4) aaabbCCbc(5) aaabbCbCc(5) aaabbbCCc(5) aaabbbCcc(6) aaabbbccc(6)
51
Equivalence Two generative grammars G and G´ are said to be equivalent if L(G) = L(G´).
52
Right-linear grammars A generative grammar where the production rules are either of the form X wY orX w where X,Y are nonterminals and w is a (possibly empty) word
53
Equivalence result If L is generated by a right-linear grammar, then L is regular A language generated by a right-linear grammar (i.e. a regular language) can always be accepted by a FSA
54
Context-free Languages There are languages that can be generated by a context-free grammar that are not regular e.g(1) S aSb (2) S L = {a n b n |n 0} Context-free grammars have a single non-terminal on the left- hand side of the production Context-free languages: the class of languages that can be generated by some context-free grammar
55
Context-sensitive languages e.g.(1)S aS´bc (2)S (3)S´ aS´bC (4)S´ (5)Cb bC (6)Cc cc There are languages that cannot be generated by a context- free grammar Language L is a context-sensitive language if there exists a context-sensitive grammar G such that either L = L(G) or L = L(G) { } Context-sensitive languages: the class of languages that can be generated by some context-sensitive grammar
56
An equivalence result Any context-sensitive language is Turing- recognizable but not vice-versa There exists Turing recognizable languages that are not context-sensitive: recursively enumerable languages
57
The Chomsky Hierarchy Regular languages Context- sensitive languages Context-free languages Recursively enumerable languages Accepted by deterministic FSA G: Right-linear grammars Accepted by linear-bounded automaton G: context-sensitive grammars Accepted by nondeterministic push-down stack automaton G: Context-Free Grammars Accepted by deterministic 1tape Turing Machine
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.